Skip to content

Unreachable match wildcard case is not reported #20251

Closed

Description

@injust

Bug Report

When a match statement on an enum is already exhaustive, mypy does not consider the wildcard case to be unreachable.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.14&enable-error-code=exhaustive-match&flags=warn-unreachable&gist=0aab275a6ddc8e9d83ea8bc676debf07

from enum import Enum, auto


class Thing(Enum):
    ONE = auto()


def main(foo: Thing) -> None:
    match foo:
        case Thing.ONE:
            pass
        case _:
            pass

Expected Behavior

The wildcard case is unreachable and should be reported as an error.

Actual Behavior

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.18.2
  • Mypy command-line flags: --warn-unreachable --enable-error-code=exhaustive-match
  • Python version used: 3.14

Activity

  1. A5rocks commented on Nov 18, 2025

    @A5rocks
    Collaborator

    Possible duplicate of #20142 though single-value enum logic is sometimes different (sadly).

  2. A5rocks commented on Nov 18, 2025

    @A5rocks
    Collaborator

    Hmm maybe if you replace pass with eg print("hi") it might warn about unreachability? Mypy doesn't flag pass for unreachability...

    (I cannot check right now)

  3. injust commented on Nov 18, 2025

    @injust
    Author

    Hmm maybe if you replace pass with eg print("hi") it might warn about unreachability? Mypy doesn't flag pass for unreachability...

    Yup, that triggered the unreachability error.

    I guess this is working as intended then?

  4. A5rocks commented on Nov 18, 2025

    @A5rocks
    Collaborator

    Yeah

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 wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions