-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
documentationtopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues
Description
Bug Report
MyPy seems to have issues when multi-variable assignments of types to their aliases are involved.
To Reproduce
Run mypy on the following two sources:
from typing import Any
typ_a = Any
typ_b = Any
def test1(x: typ_a, y: typ_b): pass
from typing import Any
typ_a, typ_b = Any, Any
def test2(x: typ_a, y: typ_b): pass
typ_a = typ_b = Any
def test3(x: typ_a, y: typ_b): pass
Expected Behavior
MyPy does not show any errors for any of the function's signatures, since they are all essentially the same.
Actual Behavior
MyPy shows the following errors for test2
and test3
:
repro2.py:4: error: Variable "repro2.typ_a" is not valid as a type
repro2.py:4: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
repro2.py:4: error: Variable "repro2.typ_b" is not valid as a type
repro2.py:7: error: Variable "repro2.typ_a" is not valid as a type
repro2.py:7: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
repro2.py:7: error: Variable "repro2.typ_b" is not valid as a type
Found 4 errors in 1 file (checked 1 source file)
Confusingly, if one merges the two source files, no errors are shown.
Your Environment
- Mypy version used: 0.800
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini
(and other config files): - Python version used: 3.9.1
- Operating system and version: Ubuntu 20.04
Metadata
Metadata
Assignees
Labels
documentationtopic-type-aliasTypeAlias and other type alias issuesTypeAlias and other type alias issues