This emits a bogus error:
type MaybeList[T] = list[T] | T
def test[X: int](items: list[X]) -> list[X]:
a: MaybeList[str | int] = list(items) #
return items
https://play.ty.dev/1757f2f8-b251-4a94-96d2-51ff3743f6d9
But this version (with a PEP 613 alias, or a legacy type alias) works:
from typing import TypeVar, TypeAlias
T = TypeVar("T")
MaybeList: TypeAlias = list[T] | T
def test[X: int](items: list[X]) -> list[X]:
a: MaybeList[str | int] = list(items)
return items
Originally posted by @DetachHead in #2314