8000 Make it an error to use a class-attribute type var outside a type by sixolet · Pull Request #3105 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Make it an error to use a class-attribute type var outside a type #3105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change error message
  • Loading branch information
sixolet committed Apr 1, 2017
commit 54ae7aab0538deb5dbf54ce3d8486afe124e2bf8
4 changes: 2 additions & 2 deletions mypy/checkmember.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ def analyze_class_attribute_access(itype: Instance,
return AnyType()

if isinstance(node.node, TypeVarExpr):
msg.fail('Type variable "{}" is invalid except as a parameter to another type'.format(
node.node.fullname() or node.node.name()), context)
msg.fail('Type variable "{}.{}" is invalid in a runtime context'.format(
itype.type.name(), name), context)
return AnyType()

if isinstance(node.node, TypeInfo):
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-typevar-values.test
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ class C:
reveal_type(l) # E: Revealed type is 'builtins.list[T`-1]'
y: C.T = x
l.append(x)
C.T # E: Type variable "T" is invalid except as a parameter to another type
A = C.T # E: Type variable "T" is invalid except as a parameter to another type
C.T # E: Type variable "C.T" is invalid in a runtime context
A = C.T # E: Type variable "C.T" is invalid in a runtime context
return l[0]

[builtins fixtures/list.pyi]
Expand Down
0