Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Unpack information oftyping.GenericAlias is not transferred from string annotations to interpreted annotations.typing.Unpacked works as expected.
A fix could be to addif getattr(t, "__unpacked__", False): return next(iter(GenericAlias(t.__origin__, ev_args))) clause here:
Lines 373 to 374 in6492492
| ifisinstance(t,GenericAlias): | |
| returnGenericAlias(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
fromtypingimportForwardReffromtypingimportTypeVarTupleTs=TypeVarTuple("Ts")typ=ForwardRef("*Ts")._evaluate({}, {"Ts":Ts},frozenset())asserttyp==next(iter(Ts))# <-- PASSES AS EXPECTEDtyp=ForwardRef("*tuple[int]")._evaluate({}, {},frozenset())asserttyp==tuple[int]# <-- PASSES BUT SHOULDN'Tasserttyp==next(iter(tuple[int]))# <-- SHOULD PASS BUT DOESN'T
Your environment
Python 3.11