Skip to content

comparison-overlap triggers for string enum members when the member name isn't the same as the comparison value #19576

Description

@bzoracler

Bug Report, To Reproduce, and Actual Behaviour

If the enum member's name to compare isn't equal to the comparing value, a false positive comparison-overlap is triggered. See mypy Playground:

fromenumimportEnumclassA(str, Enum): # Same behaviour if `class A(enum.StrEnum)`a="b"A.a=="a"# OKA.a=="b"# E: Non-overlapping equality check (left operand type: "Literal[A.a]", right operand type: "Literal['b']") [comparison-overlap]

Expected Behavior

No errors

Your Environment

  • Mypy version used: 1.17, master
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions