Skip to content

Match exhaustion fails incorrectly when matching same option twice. #17372

Description

@superosku

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions