-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
When running stubgen on a file that uses TypeAlias, the stubbed type of the type alias is TypeAlias. This prevents the actual aliased type from being recorded in the stub file, and causes mypy to emit a [valid-type] error.
To Reproduce
Create a file tmp.py:
from typing import TypeAlias
Foo: TypeAlias = tuple[int, str]Then run stubgen tmp.py.
Expected Behavior
I'm not exactly sure what the expected behavior is. I guess maybe it should behave similarly to Foo = tuple[int, str] (i.e. without the TypeAlias typehint), which stubgen includes verbatim in the stub file.
Actual Behavior
The stubbed type was only TypeAlias
$ cat out/tmp.pyi
from typing import TypeAlias
Foo: TypeAlias
Then if this stub is used, mypy emits the following error:
Invalid type alias: expression is not a valid type [valid-type]
Foo: TypeAlias
^
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.10