Skip to content

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

Open
@rouge8

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

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