Skip to content

Fix exhaustive match after unreachable cases#21527

Open
puneetdixit200 wants to merge 1 commit into
python:masterfrom
puneetdixit200:ignore-unreachable-match-cases
Open

Fix exhaustive match after unreachable cases#21527
puneetdixit200 wants to merge 1 commit into
python:masterfrom
puneetdixit200:ignore-unreachable-match-cases

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes #21517

Summary

  • keep match exhaustiveness from being updated by cases that are already unreachable
  • still type-check unreachable cases so existing diagnostics are preserved
  • add a regression for an exhaustive A | None match followed by an unreachable B() case

Tests

  • .venv\Scripts\python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-python310.test
  • .venv\Scripts\python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-unreachable-code.test
  • .venv\Scripts\python -m mypy --enable-error-code exhaustive-match -c "class A: pass\nclass B: pass\nx: A | None\nmatch x:\n case None:\n pass\n case A() as a:\n pass\n case B():\n pass"
  • .venv\Scripts\python -m pre_commit run --files mypy/checker.py test-data/unit/check-python310.test
  • git diff --check

LLM assistance was used while iterating on the patch and tests. I reviewed the change and can explain it.

@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.

mypy reports false-positive [exhaustive-match] error when there is an unreachable match

1 participant