-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
documentationpriority-0-hightopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Description
Under MyPy 0.780, the code
from typing import List
class ABC:
ABCInputType = List
x: ABC.ABCInputType = []
throws
test.py:6: error: Variable "test.ABC.ABCInputType" is not valid as a type
test.py:6: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
Found 1 error in 1 file (checked 1 source file)
while
from typing import List
ABCInputType = List
x: ABCInputType = []
works just fine.
The use of type aliases in classes seems both like a pretty legitimate use case to me (consider for example the ability to have an input type for the class as an attribute of the class as above) and also seems consistent with both the typing
documentation and mypy
's documentation, neither of which seem to mention that type aliases can only appear at the top level (only that they need to be plain assignments, as they are in the above code).
david-shiko
Metadata
Metadata
Assignees
Labels
documentationpriority-0-hightopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues