You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeAliasType is always generic when type_params=() is passed. #124498
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.
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[()]
Activity
pythongh-124498: Fix `TypeAliasType` not to be generic, when `type_pa…
gh-124498: Fix `TypeAliasType` not to be generic, when `type_params=(…
pythongh-124498: Fix `TypeAliasType` not to be generic, when `type_pa…
pythongh-124498: Fix `TypeAliasType` not to be generic, when `type_pa…
[3.12] gh-124498: Fix `TypeAliasType` not to be generic, when `type_p…
[3.13] gh-124498: Fix `TypeAliasType` not to be generic, when `type_p…