Fix crash in match statement when subject expression have unpacked tuple - #21989
Open
EmmanuelNiyonshuti wants to merge 2 commits into
Open
EmmanuelNiyonshuti wants to merge 2 commits into
EmmanuelNiyonshuti wants to merge 2 commits into
Conversation
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Fixes #21468
Match subject expressions containing an unpacked tuple crash mypy. This looks like a regression introduced by #16905, which asserts that the subject expression's items line up one-to-one with its inferred type's items. well, because starred subject expression is flattened out, the type ends up with more items than the expression.
This PR is trivial because it returns early instead of asserting, to prevent the crash. Unfortunately, this doesn't preserve narrowing for unpacked tuples in the way #16905 seems to have been heading toward. I've kept this PR scoped to just preventing this crash; narrowing can (probably will, I don't think I have the bandwidth for it right now 😅 ) be handled in a separate PR.