Skip to content

Exhaustiveness checking false positives when using match self or match self.value inside an Enum #15186

Closed

Description

@rouge8

Bug Report

When using match self or match self.value inside a method or property on an Enum, mypy reports an error on assert_never(). This works as expected in pyright.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=6f0acfbf4f32fd48e7d6284b15368919

Actual Behavior

main.py:17: error: Argument 1 to "assert_never" has incompatible type "MyEnum"; expected "NoReturn"  [arg-type]
main.py:27: error: Argument 1 to "assert_never" has incompatible type "Union[str, str]"; expected "NoReturn"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.2.0 (compiled: yes)
  • Mypy command-line flags: --show-error-codes
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: Python 3.11.1

Activity

  1. frou commented on Jul 18, 2023

    @frou

    In the first method, it seems to be case self.a / case self.b that Mypy is choking on, not match self. Because it works when changing them to case MyEnum.a / case MyEnum.b

  2. frou commented on Jul 18, 2023

    @frou

    Possibly related issue: #12107

  3. MestreLion commented on Aug 3, 2023

    @MestreLion
    Contributor

    Most likely a duplicate of #10910

  4. added a commit that references this issue on Aug 3, 2025
    9d3a052
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-reachabilityDetecting unreachable code

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions