-
-
Notifications
You must be signed in to change notification settings - Fork 128
Fix subscription of Unpack causing nested Unpacks to not be resolved correctly #480
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2bd8891
Fix Unpack Alias not being subscriptable, causing nested Unpacks to fail
Daraan 8021de6
remove test for invalid type form
Daraan 23feb2e
Rewording and removed test related to invalid form
Daraan ae699f2
rewording and trimming
Daraan 6812586
reduced tests and no longer based on TypeAliasType
Daraan 6f3f1a6
Updated changelog
Daraan db36b48
Merge branch 'main' into unpack/nested-subscription
Daraan 90c4f38
Removed subTests or made to their own function
Daraan b97095b
Merge branch 'main' into unpack/nested-subscription
Daraan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5779,6 +5779,42 @@ class D(Protocol[T1, T2, Unpack[Ts]]): pass | |
| with self.assertRaises(TypeError): | ||
| klass[int] | ||
|
|
||
| def test_substitution(self): | ||
| Ts = TypeVarTuple("Ts") | ||
| unpacked_str = Unpack[Ts][str] | ||
| with self.subTest("Check substitution result"): | ||
|
||
| self.assertIs(unpacked_str, str) | ||
|
|
||
| @skipUnless(TYPING_3_11_0, "Needs Issue #103 for <3.11") | ||
| def test_nested_unpack(self): | ||
| T = TypeVar('T') | ||
| Ts = TypeVarTuple("Ts") | ||
| Variadic = Tuple[int, Unpack[Ts]] | ||
| # Tuple[int, int, Tuple[str, int]] | ||
| direct_subscription = Variadic[int, Tuple[str, int]] | ||
| # Tuple[int, int, Tuple[*Ts, int]] | ||
| TupleAliasTs = Variadic[int, Tuple[Unpack[Ts], int]] | ||
|
|
||
| # if this fails all below are likely to fail too | ||
| # Tuple[int, int, Tuple[str, int]] | ||
| recursive_unpack = TupleAliasTs[str] | ||
| self.assertEqual(direct_subscription, recursive_unpack) | ||
| self.assertEqual(get_args(recursive_unpack), (int, int, Tuple[str, int])) | ||
|
|
||
| TupleAliasTsT = Variadic[Tuple[Unpack[Ts], T]] | ||
| # Equivalent Forms | ||
| with self.subTest("Equivalence of variadic arguments"): | ||
|
||
| nested_tuple_bare = TupleAliasTsT[str, int, object] | ||
| self.assertEqual(nested_tuple_bare, TupleAliasTsT[Unpack[Tuple[str, int, object]]]) | ||
| self.assertEqual(nested_tuple_bare, TupleAliasTsT[Unpack[Tuple[str, int]], object]) | ||
| self.assertEqual(nested_tuple_bare, TupleAliasTsT[Unpack[Tuple[str]], Unpack[Tuple[int]], object]) | ||
| self.assertEqual(get_args(nested_tuple_bare), (int, Tuple[str, int, object],)) | ||
|
|
||
| with self.subTest("With Callable and Unpack"): | ||
| # Tuple[int, (str, int) -> object] | ||
| CallableAliasTsT = Variadic[Callable[[Unpack[Ts]], T]] | ||
| callable_fully_subscripted = CallableAliasTsT[Unpack[Tuple[str, int]], object] | ||
| self.assertEqual(get_args(callable_fully_subscripted), (int, Callable[[str, int], object],)) | ||
|
|
||
| class TypeVarTupleTests(BaseTestCase): | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.