Skip to content

[1.16 regression] determining exhaustive match on an enum with type members #19151

Closed
@delfick

Description

@delfick

Hi,

I continued looking at how the codebase I work on responds to the upcoming mypy 1.16 release and I believe I found another bug

import datetime
import enum
from typing import assert_never


class ValueType(enum.Enum):
    BOOLEAN = bool
    DATE = datetime.date
    DATETIME = datetime.datetime


value_type: ValueType = ValueType.BOOLEAN

match value_type:
    case ValueType.BOOLEAN:
        pass
    case ValueType.DATE:
        pass
    case ValueType.DATETIME:
        pass
    case _:
        assert_never(value_type)

On mypy 1.16 I get this error

a.py:22: error: Argument 1 to "assert_never" has incompatible type "ValueType"; expected "Never"  [arg-type]

As far as I can tell this should be correct and I'm unsure why it doesn't think I have an exhaustive match.

Your Environment

  • Mypy version used: release-1.16 (revision 96525a2, built locally with mypy_mypyc-wheels for cp312-macosx_arm64)
  • Mypy command-line flags: mypy a.py
  • Mypy configuration options from mypy.ini (and other config files): no config
  • Python version used: python3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions