I received plenty of interesting comments regarding my previous question, so that I indulge myself in another one.
a.py, you import
TypeAlias from module
from typing import TypeAlias
b.py, you import all of module
a and use
from a import * t:TypeAlias = int
Pyright raises an error:
error: Expression of type "Type[int]" cannot be assigned to declared type "TypeAlias" "Type[type]" is incompatible with "Type[TypeAlias]"
However, if I import TypeAlias direcly in module b, it works!
# from a import * from typing import TypeAlias t:TypeAlias = int
It also works if I use the extended name of
TypeAlias, that is,
# from a import * import typing t:typing.TypeAlias = int
typing.py source code, it is mentioned that
TypeAlias is not a type-as-usual, but kind of a “Special marker”. It is emphasized that its use is strictly restricted to the form above, but nothing is specified about importation.
Could anybody explain how it should be used properly?