Lenient handling of *tuple[Any, ...] (part 2) - #22006
Open
ilevkivskyi wants to merge 3 commits into
Open
ilevkivskyi wants to merge 3 commits into
ilevkivskyi wants to merge 3 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
JukkaL
approved these changes
Sep 21, 2026
JukkaL
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, looks good -- just a few comments.
| x, y, z = t | ||
| reveal_type(x) # N: Revealed type is "builtins.int" | ||
| reveal_type(y) # N: Revealed type is "Any" | ||
| reveal_type(z) # N: Revealed type is "builtins.str" |
Collaborator
There was a problem hiding this comment.
Test also the case with two lvalues (tuple expands to empty).
| # Slicing support for variadic tuples is currently best effort, the key idea is to not give an error. | ||
| reveal_type(t[1:3:2]) # N: Revealed type is "builtins.tuple[builtins.int | Any | builtins.str, ...]" | ||
| reveal_type(t1[1:3:2]) # N: Revealed type is "builtins.tuple[builtins.int | Any, ...]" | ||
| reveal_type(t2[1:3:2]) # N: Revealed type is "builtins.tuple[Any | builtins.str, ...]" |
Collaborator
There was a problem hiding this comment.
Should t1[::0] generate an error, since it doesn't work at runtime (and doesn't make sense)?
Member
Author
There was a problem hiding this comment.
Yes, we do give an error for 0 stride (but the error message is bad). I will probably change the logic slightly to give a better error message.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ref #19858
This (smaller) part handles various edge cases that should be handled leniently in presence of
*tuple[Any, ...]: indexing and unpacking. Everything is straightforward, similar to first part #22001, the tests are focused on situations that previously gave errors.cc @JukkaL