Skip to content

IntEnum literals are not considerable comparable with ints #16327

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

fromenumimportIntEnumclassCardVal(IntEnum):
VAL_A=1VAL_2=2try:
assertCardVal.VAL_A==1exceptAssertionError:
pass# So we see the second error in mypyassertCardVal.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