Skip to content

Avoid crash for starred match subject tuples#21499

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
python:masterfrom
Sean-Kenneth-Doherty:fix-match-subject-unpack-crash
Open

Avoid crash for starred match subject tuples#21499
Sean-Kenneth-Doherty wants to merge 1 commit into
python:masterfrom
Sean-Kenneth-Doherty:fix-match-subject-unpack-crash

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 17, 2026

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 TupleType items, so preserving the normal tuple assertion there can crash on subjects such as match 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 testMatchSequencePatternSubjectWithStarExprNoCrash
  • PATH=.venv/bin:$PATH .venv/bin/python runtests.py check-python310.test
  • TMPDIR=/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 mypyc
  • PATH=$PWD/.venv/bin:$PATH .venv/bin/python runtests.py lint
  • git diff --check

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

Crash in match-statement's subject expression with an unpacked tuple

1 participant