Skip to content

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

@ambv

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

import enum from typing import Literal type One = Literal[1] type Two = Literal[2] type Three = Literal[3] def option(arg: One | Two | Three) -> None: ... class MyEnum(enum.IntEnum): ONE = 1 TWO = 2 THREE = 3 option(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