python / typing_extensions

Backported and experimental type hints for Python
Other
446 stars 110 forks source link

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

Closed Daraan closed 1 month ago

Daraan commented 1 month 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.