Skip to content

MyIntEnum.ONE should be passable to functions expecting Literal[1] arguments #19616

Description

@ambv

Bug Report

This is related but distinct from #19576, #16327, and #17162. It's also not specific to IntEnums, but I use them in the example for clarity. StrEnums as well as enums based on (int, Enum), or (str, Enum), etc.

To Reproduce

importenumfromtypingimportLiteral
type One=Literal[1]
type Two=Literal[2]
type Three=Literal[3]
defoption(arg: One|Two|Three) ->None:
...
classMyEnum(enum.IntEnum):
ONE=1TWO=2THREE=3option(MyEnum.TWO) # error: Argument 1 to "option" has incompatible type "Literal[MyEnum.TWO]"; expected "Literal[1, 2, 3]" [arg-type]

Expected Behavior

No error reported.

Actual Behavior

The error in the comment in the example is a false positive. This code works fine at runtime.

Your Environment

  • Mypy version used: master as of 0d791b2
  • Python version used: 3.13

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions