-
-
Notifications
You must be signed in to change notification settings - Fork 117
TypeAliasType not raising TypeError when it is has no parameters #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Currently the 3.13.0 def test_subscription_without_type_params(self):
Simple = TypeAliasType("Simple", int)
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[int]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[[]]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
Simple[()]
# A TypeVar in the value does not allow subscription
T = TypeVar('T')
MissingTypeParamsErr = TypeAliasType("MissingTypeParamsErr", List[T])
self.assertEqual(MissingTypeParamsErr.__type_params__, ())
self.assertEqual(MissingTypeParamsErr.__parameters__, ())
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[int]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[[]]
with self.assertRaises(TypeError, msg="Only generic type aliases are subscriptable"):
MissingTypeParamsErr[()]
# However, providing type_params=() argument allows subscription
MissingTypeParams = TypeAliasType("MissingTypeParams", List[T], type_params=())
self.assertEqual(MissingTypeParams.__type_params__, ())
self.assertEqual(MissingTypeParams.__parameters__, ())
# These do not raise
MissingTypeParams[int]
MissingTypeParams[[]]
MissingTypeParams[()]
# These do not raise
Simple2 = TypeAliasType("Simple2", int, type_params=())
Simple2[int]
Simple2[[]]
Simple2[()] EDIT: This behavior has now been changed and errors are raised like expected. #473 will align the behavior with the latest cpython implementation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When using a
TypeAliasType
without type_params it should raise an error which it currently doesn't:However, currently in 3.12+ when using
type_params=()
the code unexpectedly allows subscription.See also cpython issue #124498 and its PR. This issue likely needs an upstream decision first if the following case is intended or a bug:
Also related:
TypeVar
substitution does not work correctly withTypeAliasType
pydantic/pydantic#6158The text was updated successfully, but these errors were encountered: