Skip to content

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

Merged
JelleZijlstra merged 9 commits into
python:mainfrom
Daraan:unpack/nested-subscription
Oct 21, 2024
Merged

Fix subscription of Unpack causing nested Unpacks to not be resolved correctly#480
JelleZijlstra merged 9 commits into
python:mainfrom
Daraan:unpack/nested-subscription

Conversation

@Daraan

@DaraanDaraan commented Oct 4, 2024

Copy link
Copy Markdown
Contributor

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.

fromtyping_extensionsimportTypeVarTuple, UnpackTs=TypeVarTuple("Ts")
assertUnpack[Ts][str] isstr

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.

@JelleZijlstraJelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks close to ready.

Comment threadCHANGELOG.md Outdated
subscripted objects) had wrong parameters if they were directly
subscripted with an `Unpack` object.
Patch by [Daraan](https://github.com/Daraan).
- Fix error in subscription of Unpack aliases causing nested Unpacks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Fix error in subscription of Unpack aliases causing nested Unpacks
- Fix error in subscription of `Unpack` aliases causing nested Unpacks

Comment threadsrc/test_typing_extensions.py Outdated
def test_substitution(self):
Ts = TypeVarTuple("Ts")
unpacked_str = Unpack[Ts][str]
with self.subTest("Check substitution result"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for subTest for a single test

Comment threadsrc/test_typing_extensions.py Outdated

TupleAliasTsT = Variadic[Tuple[Unpack[Ts], T]]
# Equivalent Forms
with self.subTest("Equivalence of variadic arguments"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use subTest in a loop. This one should probably just be a separate test method.

Daraanand others added 2 commits October 21, 2024 18:08
formatting to changelog
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Daraan <github.blurry@9ox.net>
@JelleZijlstra
JelleZijlstra merged commit a2abfe6 into python:mainOct 21, 2024
@Daraan
Daraan deleted the unpack/nested-subscription branch October 21, 2024 17:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested use of Unpack in alias from TypeAliasType causes TypeError on Python 3.11

2 participants

@Daraan@JelleZijlstra