Bug report
Unpack information of typing.GenericAlias is not transferred from string annotations to interpreted annotations. typing.Unpacked works as expected.
A fix could be to add if getattr(t, "__unpacked__", False): return next(iter(GenericAlias(t.__origin__, ev_args))) clause here:
|
if isinstance(t, GenericAlias): |
|
return GenericAlias(t.__origin__, ev_args) |
NOTE: This bug is in typing's internal API and I don't think there's issues in the public API (but haven't looked hard). However, this issue pops up quickly if you try to do anything wrt PEP 646 typing at runtime.
Minimal example
from typing import ForwardRef
from typing import TypeVarTuple
Ts = TypeVarTuple("Ts")
typ = ForwardRef("*Ts")._evaluate({}, {"Ts": Ts}, frozenset())
assert typ == next(iter(Ts)) # <-- PASSES AS EXPECTED
typ = ForwardRef("*tuple[int]")._evaluate({}, {}, frozenset())
assert typ == tuple[int] # <-- PASSES BUT SHOULDN'T
assert typ == next(iter(tuple[int])) # <-- SHOULD PASS BUT DOESN'T
Your environment
Python 3.11
Linked PRs
Bug report
Unpack information of
typing.GenericAliasis not transferred from string annotations to interpreted annotations.typing.Unpackedworks as expected.A fix could be to add
if getattr(t, "__unpacked__", False): return next(iter(GenericAlias(t.__origin__, ev_args)))clause here:cpython/Lib/typing.py
Lines 373 to 374 in 6492492
NOTE: This bug is in typing's internal API and I don't think there's issues in the public API (but haven't looked hard). However, this issue pops up quickly if you try to do anything wrt PEP 646 typing at runtime.
Minimal example
Your environment
Python 3.11
Linked PRs
typing.get_type_hintswith unpacked*tuple(PEP 646) #101031typing.get_type_hintswith unpacked*tuple(PEP 646) (GH-101031) #101254