[New-bugs-announce] [issue46655] typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms
Gregory Beauregard
report at bugs.python.org
Sun Feb 6 02:30:06 EST 2022
New submission from Gregory Beauregard <greg at greg.red>:
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 `TypeError: Plain typing.TypeAlias is not valid as type argument` at runtime.
Examples offhand:
from typing import TypeAlias, get_type_hints
class A:
a: "TypeAlias" = int
get_type_hints(A)
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.
----------
components: Library (Lib)
messages: 412618
nosy: GBeauregard
priority: normal
severity: normal
status: open
title: typing.TypeAlias is not in the list of allowed plain _SpecialForm typeforms
type: behavior
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46655>
_______________________________________
More information about the New-bugs-announce
mailing list