Avoid crash for starred match subject tuples#21499
Open
Sean-Kenneth-Doherty wants to merge 1 commit into
Open
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.
This avoids recursively narrowing tuple-expression subject items when the subject tuple contains a starred expression. Those expressions do not have a one-to-one correspondence with the inferred
TupleTypeitems, so preserving the normal tuple assertion there can crash on subjects such asmatch foo, *bar:. Ordinary tuple expressions still keep the existing length assertion and recursive item narrowing.A regression case was added to
check-python310.test.AI assistance was used in preparing this change; I am responsible for the submitted patch and follow-up review.
Verification:
.venv/bin/python -m mypy --show-traceback --python-version 3.14 -c $'foo = 0\nbar = (1, 2)\nmatch foo, *bar:\n case _:\n pass\n'PATH=.venv/bin:$PATH .venv/bin/python runtests.py testMatchSequencePatternSubjectWithStarExprNoCrashPATH=.venv/bin:$PATH .venv/bin/python runtests.py check-python310.testTMPDIR=/home/sean/.cache/codex-tmp/go-build GOTMPDIR=/home/sean/.cache/codex-tmp/go-build PATH=.venv/bin:$PATH .venv/bin/pre-commit run --files mypy/checker.py test-data/unit/check-python310.test.venv/bin/python -m compileall -q mypy/checker.py.venv/bin/python -m mypy --config-file mypy_self_check.ini --no-incremental --num-workers 0 -p mypy -p mypycPATH=$PWD/.venv/bin:$PATH .venv/bin/python runtests.py lintgit diff --check