Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
Oct 21, 2024

Conversation

Daraan
Copy link
Contributor

@Daraan Daraan commented Oct 4, 2024

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.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

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.

CHANGELOG.md Outdated
@@ -16,6 +16,8 @@
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
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

def test_substitution(self):
Ts = TypeVarTuple("Ts")
unpacked_str = Unpack[Ts][str]
with self.subTest("Check substitution result"):
Copy link
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


TupleAliasTsT = Variadic[Tuple[Unpack[Ts], T]]
# Equivalent Forms
with self.subTest("Equivalence of variadic arguments"):
Copy link
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.

Daraan and 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:main Oct 21, 2024
21 checks passed
@Daraan Daraan deleted the unpack/nested-subscription branch October 21, 2024 17:26
Sign up for free to 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