Bug report
Bug description:
I realized that the type_params parameter of TypeAliasType behaves differently when it is omitted vs passing an empty tuple (), in the latter case the resulting instance is always subscriptable. I doubt this is an undocumented feature.
from typing import List, TypeAliasType, TypeVar # < Errors like expected > Simple = TypeAliasType("Simple", int) try: Simple[int] except TypeError: print("Expected: Simple is not subcriptable") # Not allowed assignment T = TypeVar('T') MissingTypeParamsErr = TypeAliasType("MissingTypeParamsErr", List[T]) assert MissingTypeParamsErr.__type_params__ == () assert MissingTypeParamsErr.__parameters__ == () try: MissingTypeParamsErr[int] except TypeError: print("Expected: Simple is not subcriptable") # < unexpected cases > MissingTypeParams = TypeAliasType("MissingTypeParams", List[T], type_params=()) assert MissingTypeParams.__type_params__ == () assert MissingTypeParams.__parameters__ == () # These cases do not raise an error MissingTypeParams[int] MissingTypeParams[[]] MissingTypeParams[()] # This also do not raise an error Simple2 = TypeAliasType("Simple2", int, type_params=()) assert Simple2 .__type_params__ == () assert Simple2 .__parameters__ == () Simple2[int] Simple2[[]] Simple2[()]
CPython versions tested on:
3.13
Operating systems tested on:
Linux