Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
I realized that thetype_params parameter ofTypeAliasType 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.
fromtypingimportList,TypeAliasType,TypeVar# < Errors like expected >Simple=TypeAliasType("Simple",int)try:Simple[int]exceptTypeError:print("Expected: Simple is not subcriptable")# Not allowed assignmentT=TypeVar('T')MissingTypeParamsErr=TypeAliasType("MissingTypeParamsErr",List[T])assertMissingTypeParamsErr.__type_params__== ()assertMissingTypeParamsErr.__parameters__== ()try:MissingTypeParamsErr[int]exceptTypeError:print("Expected: Simple is not subcriptable")# < unexpected cases >MissingTypeParams=TypeAliasType("MissingTypeParams",List[T],type_params=())assertMissingTypeParams.__type_params__== ()assertMissingTypeParams.__parameters__== ()# These cases do not raise an errorMissingTypeParams[int]MissingTypeParams[[]]MissingTypeParams[()]# This also do not raise an errorSimple2=TypeAliasType("Simple2",int,type_params=())assertSimple2 .__type_params__== ()assertSimple2 .__parameters__== ()Simple2[int]Simple2[[]]Simple2[()]
CPython versions tested on:
3.13
Operating systems tested on:
Linux