Mypy shows an incorrect error when the same option is twice in an match statement.
To Reproduce
from typing import assert_never
from enum import Enum, auto
class Medal(Enum):
gold: auto
silver: auto
bronze: auto
def fail_1(medal: Medal) -> None:
match medal:
case Medal.gold:
pass
case Medal.silver | Medal.silver:
pass
case Medal.bronze:
pass
case _:
assert_never(medal) # is "Literal[Medal.silver]" should be NoReturn
def fail_2(medal: Medal) -> None:
match medal:
case Medal.gold:
pass
case Medal.silver | Medal.silver:
pass
case _:
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
Mypy shows an incorrect error when the same option is twice in an match statement.
To Reproduce
Expected Behavior
See the comments in the example python code.
It should either fail on
case Medal.silver | Medal.silver:orfail_1should assert never properly andfail_2should showMedal.bronzeinstead ofMedal.silverActual Behavior
See the python example.
Your Environment
Mypy version used:
Python version used:
Mypy command-line flags: none
Mypy configuration options from
mypy.ini(and other config files): none