python / typing_extensions

Backported and experimental type hints for Python
Other
425 stars 106 forks source link

Fix subscription of Unpack causing nested Unpacks to not be resolved correctly #480

Open Daraan opened 1 day ago

Daraan commented 1 day ago

The current Unpack alias backport had an issue that it did not resolve correctly during substition. This PR fixes that the following should hold, or rather that the subscription does not raise a TypeError.

from typing_extensions import TypeVarTuple, Unpack
Ts = TypeVarTuple("Ts")
assert Unpack[Ts][str] is str

This fixes #474 and was solved by simply adding the Python 3.12+ code to the alias classes.

Sitenote: This is only slightly related to #103, the code sample there also did not work in 3.11 after the backport was used. However, the error is not related and still persists for <=3.10.