Open
Description
from typing import TypeVar, TypeAlias
T = TypeVar("T")
TAlias: TypeAlias = T
def foo(
t1: TAlias[int], # no error
t2: TAlias, # error: Missing type parameters for generic type "TAlias"
) -> None: ...
Treating it as a generic type and not as TypeVar
is incorrect as at runtime it is not subscriptable:
Traceback (most recent call last):
File "test.py", line 7, in <module>
t1: TAlias[int], # no error
TypeError: 'TypeVar' object is not subscriptable
Strangely, the correct error is reported when the TypeAlias
is omitted.
from typing import TypeVar, TypeAlias
T = TypeVar("T")
TAlias = T # error: Type variable "__main__.T" is invalid as target for type alias [misc]