-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable codetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
mypy thinks that a match statement covering all values of an enum is not exhaustive, when inside a function that has a reference to a global variable beforehand.
For some reason, the reference to the global variable obj before the match statement makes a difference.
To Reproduce
from enum import Enum, auto
class Thing(Enum):
ONE = auto()
def main(foo: Thing) -> None:
print(obj)
match foo:
case Thing.ONE:
pass
obj = object()Expected Behavior
The match statement is exhaustive, so mypy should not error.
And if you add a case _: pass like the note suggests (https://mypy-play.net/?mypy=latest&python=3.14&enable-error-code=exhaustive-match&flags=warn-unreachable&gist=9b375e563c684c62a2f4b4f24f30a679), then mypy should warn that the wildcard case is unreachable.
Actual Behavior
main.py:11: error: Match statement has unhandled case for values of type "Any | Any" [exhaustive-match]
main.py:11: note: If match statement is intended to be non-exhaustive, add `case _: pass`
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.18.2
- Mypy command-line flags:
--enable-error-code=exhaustive-match - Python version used: 3.14
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-reachabilityDetecting unreachable codeDetecting unreachable codetopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder