Closed as not planned
Description
Bug Report
Exhaustive match on enums fails if no intermediate alias of the match variable is given.
To Reproduce
from enum import Enum
class Choices(str, Enum):
A="A"
B="B"
def matcher_implicit(a: str) -> str:
match Choices(a):
case Choices.A:
return 'ok'
case Choices.B:
return 'schmok'
def matcher_alias(a: str) -> str:
explicit_alias = Choices(a)
match explicit_alias:
case Choices.A:
return 'ok'
case Choices.B:
return 'schmok'
You can run this on https://mypy-play.net/?mypy=latest&python=3.11, and see that only matcher_implicit
fails, but there's no reason why it should!
Expected Behavior
Both should typecheck correctly
Actual Behavior
The first one fails typechecking, with a fake "missing return statement" error emitted.
Your Environment
- Mypy version used: 1.5.1 and 1.6.0 (fails on both).
- sample fails on mypy-play.