-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms #90813
Comments
typing.TypeAlias is allowed to be bare, but it's not listed in the list of types in typing._type_check that are allowed to be bare. This means it's possible to reach the wrong error Examples offhand: from typing import Annotated, TypeAlias
b: Annotated[TypeAlias, ""] = int There's likely more and/or more realistic ways to trigger the problem. Anything that triggers typing._type_check on typing.TypeAlias will give this error (TypeError: Plain typing.TypeAlias is not valid as type argument). I will fix this by adding TypeAlias to the list of typing special forms allowed to be bare/plain. I intend to move these to their own named var to reduce the chance of types not getting added in the future. |
Looks like the more likely use case would be PEP-563: from __future__ import annotations
from typing import TypeAlias, get_type_hints
import typing
class C:
a: TypeAlias = int
print(get_type_hints(C)) This prints Traceback (most recent call last):
File "C:\Users\gvanrossum\cpython\t.py", line 9, in <module>
print(get_type_hints(C))
File "C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\lib\typing.py", line 1808, in get_type_hints
value = _eval_type(value, base_globals, base_locals)
File "C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\lib\typing.py", line 326, in _eval_type
return t._evaluate(globalns, localns, recursive_guard)
File "C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\lib\typing.py", line 690, in _evaluate
type_ = _type_check(
File "C:\Users\gvanrossum\AppData\Local\Programs\Python\Python310\lib\typing.py", line 171, in _type_check
raise TypeError(f"Plain {arg} is not valid as type argument") |
Closing since the issue has been fixed (I cannot reproduce it on 3.12 or main). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: