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