Skip to content

Non-overlapping equality not detected inside of pattern matching case statements. #14965

Closed

Description

@HexDecimal

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

Activity

  1. hauntsaninja commented on Jan 28, 2026

    @hauntsaninja
    Collaborator

    --warn-unreachable does the right thing here (and #20660 I think improves behaviour on some of your test cases)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-match-statementPython 3.10's match statementtopic-overlapOverlapping equality check

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions