Skip to content

IntEnum literals are not considerable comparable with ints #16327

Open
@javajawa

Description

@javajawa

Bug Report

The handling of types for IntEnum literals shows no overlap with int literals.
The handling for int variables appears to be correct,

To Reproduce

playground

from enum import IntEnum


class CardVal(IntEnum):
    VAL_A = 1
    VAL_2 = 2

try:
    assert CardVal.VAL_A == 1
except AssertionError:
    pass # So we see the second error in mypy

assert CardVal.VAL_2 == 2

Expected Behavior

The type of CardVal.VAL_A gets erased to something considered comparable to Literal[1]

Actual Behavior

From the playground link, using python 3.10 / mypy 1.6.1:

main.py:9: error: Non-overlapping equality check (left operand type: "Literal[CardVal.VAL_A]", right operand type: "Literal[1]")  [comparison-overlap]
main.py:13: error: Non-overlapping equality check (left operand type: "Literal[CardVal.VAL_2]", right operand type: "Literal[2]")  [comparison-overlap]
Found 2 errors in 1 file (checked 1 source file)

The same behaviour has been seen locally with python 3.11 / mypy 1.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions