Description
Bug Report
--strict-equality
does not check for non-overlapping types during a match case statement.
Case statements with Literal patterns or Constant value patterns are not checked and will not error when always-false.
The docs for --strict-equality
state that these kinds of always-false comparisons are checked, though it does not mention pattern matching specifically. Otherwise this is a feature request to support checks in pattern matching case statements.
To Reproduce
Example script with various combinations of pattern matching features. All cases should error, but many don't:
https://mypy-play.net/?mypy=latest&python=3.11&flags=strict&gist=1832e8c73685a4e2ae2f84873b7573ca
Smallest reproducible sample:
match 0:
case "str":
pass
Expected Behavior
Always-false cases in pattern matching should be detected by Mypy with the --strict
or --strict-equality
flags and treated as errors.
All case statements in the the example should fail with Non-overlapping equality check ... [comparison-overlap]
.
Actual Behavior
Always-false case statements pass Mypy without error.
Only the cases where the matched value is assigned a name before being compared with a guard case ... if ...:
are detected.
Your Environment
- Mypy version used: 1.1.1/master
- Mypy command-line flags:
--strict
- Python version used: 3.11