mypy
mypy copied to clipboard
"Type variable is invalid as target for type alias" error on new union syntax when not using `TypeAlias` type
from typing import TypeVar, TypeAlias
T = TypeVar("T")
MaybeList = T | list[T] # error: Type variable "__main__.T" is invalid as target for type alias
MaybeList2: TypeAlias = T | list[T] # no error
related to: #13376
workaround: use new python 3.12 type alias syntax
type MaybeList[T] = T | list[T]