Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add flag to raise error if match statement does not match exaustively #19144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
Loading
from
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
02796d9
Add check for exhaustive match statements
Don-Burns May 23, 2025
3aaa98b
Add flag for exhaustive match statements
Don-Burns May 23, 2025
6b613f5
Update docs for exhaustive match statements
Don-Burns May 23, 2025
3341b4b
Add flag to mypy_primer
Don-Burns May 23, 2025
a186cc8
Revert "Add flag to mypy_primer"
Don-Burns May 24, 2025
ec55c81
Move tests to 3.10 file so only run on >=3.10
Don-Burns May 24, 2025
8ce5b6a
Rename flag to better follow other flags
Don-Burns May 24, 2025
3581ec9
Fix doc gen error
Don-Burns May 24, 2025
0f9ed6a
Set default True for CI run, will revert before merge
Don-Burns May 24, 2025
62e4089
Revert "Set default True for CI run, will revert before merge"
Don-Burns May 24, 2025
abf7e98
Add explicit error code - change [misc] -> [exhaustive-match]
Don-Burns May 24, 2025
6a525f7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2025
7dc7c01
Add missed docs
Don-Burns May 24, 2025
3ab9848
fixup! Add missed docs
Don-Burns May 24, 2025
1a3e359
fixup! fixup! Add missed docs
Don-Burns May 24, 2025
fecd37d
Change to error code only for exhaustive match
Don-Burns May 24, 2025
525924f
Merge doc literal paragraph
Don-Burns May 26, 2025
f798b43
Empty commit to trigger CI
Don-Burns May 27, 2025
9b200ac
Apply suggestions to remove whitespace from tests
Don-Burns May 28, 2025
681a327
fixup! Apply suggestions to remove whitespace from tests
Don-Burns May 28, 2025
d219871
Add test for more complex narrowing use case
Don-Burns May 28, 2025
914bff4
fixup! Add test for more complex narrowing use case
Don-Burns May 28, 2025
4cc25fe
Merge branch 'master' into feat/exhaustive-match
Don-Burns May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge doc literal paragraph
  • Loading branch information
Don-Burns committed May 26, 2025
commit 525924f0e29939d401b90561d03d1ea10837bf72
1 change: 0 additions & 1 deletion 1 docs/source/literal_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ If we forget to handle one of the cases, mypy will generate an error:
assert_never(direction) # E: Argument 1 to "assert_never" has incompatible type "Direction"; expected "NoReturn"

Exhaustiveness checking is also supported for match statements (Python 3.10 and later).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be expanded instead of adding a new paragraph:

Suggested change
Exhaustiveness checking is also supported for match statements (Python 3.10 and later).
Exhaustiveness checking is also supported for match statements (Python 3.10 and later). With
:option:`--disallow-inexhaustive-match-statements <mypy --disallow-inexhaustive-match-statements>`,
mypy will even warn if match statements are inexhaustive.

(not sure that's better than your current approach now that I write it out, actually)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right here 👍
Changed to 1 paragraph


For match statements specifically, inexhaustive matches can be caught
without needing to use ``assert_never`` by using
:option:`--enable-error-code exhaustive-match <mypy --enable-error-code>`.
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.