Memo:
- mypy test.py
- mypy 1.19.1
- Python 3.14.0
Using the type alias created by a type statement, mypy gives no error as shown below:
type TA[T] = T
v: TA[int] = 100 # No error
But using the type alias created by TypeAliasType which is the base of a type statement, mypy gives the error as shown below:
*Memo:
pyright, pyrefly and ty work for TypeAliasType.
from typing import TypeVar, TypeAliasType
T = TypeVar('T')
TA = TypeAliasType('TA', value=T, type_params=(T,))
v: TA[int] = 100 # Error
error: Variable "test.TA" is not valid as a type
Basically, a base class works like the old syntax of generics TypeVar, TypeVarTuple and ParamSpec but the type alias created by TypeAliasType doesn't work.