New submission from Gregory Beauregard <g...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue46655>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to