You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Match exhaustion fails incorrectly when matching same option twice. #17372
Mypy shows an incorrect error when the same option is twice in an match statement.
To Reproduce
fromtypingimportassert_neverfromenumimportEnum, autoclassMedal(Enum):
gold: autosilver: autobronze: autodeffail_1(medal: Medal) ->None:
matchmedal:
caseMedal.gold:
passcaseMedal.silver|Medal.silver:
passcaseMedal.bronze:
passcase _:
assert_never(medal) # is "Literal[Medal.silver]" should be NoReturndeffail_2(medal: Medal) ->None:
matchmedal:
caseMedal.gold:
passcaseMedal.silver|Medal.silver:
passcase _:
assert_never(medal) # is "Literal[Medal.silver]" should be "Literal[Medal.bronze]"
Expected Behavior
See the comments in the example python code.
It should either fail on case Medal.silver | Medal.silver: or fail_1 should assert never properly and fail_2 should show Medal.bronze instead of Medal.silver
Actual Behavior
See the python example.
Your Environment
Mypy version used:
$ mypy --version
mypy 1.10.0 (compiled: yes)
Python version used:
$ python --version
Python 3.12.2
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
The enum is mistakenly defined. If you use gold = auto() (instead of the incorrect gold: auto that doesn't work at runtime), mypy does the expected thing.
Future versions of mypy will highlight this error better if you use --warn-unreachable (I'm improving this in #20660)
Activity
hauntsaninja commentedon Jan 28, 2026
The enum is mistakenly defined. If you use
gold = auto()(instead of the incorrectgold: autothat doesn't work at runtime), mypy does the expected thing.Future versions of mypy will highlight this error better if you use
--warn-unreachable(I'm improving this in #20660)Improve reachability in narrowing logic (#20660)