`comparison-overlap` triggers for string enum members when the member name isn't the same as the comparison value
Open
Nobody has claimed this yet.
bug
false-positive
topic-enum
topic-literal-types
topic-overlap
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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:
from enum import Enum
class A(str, Enum): # Same behaviour if `class A(enum.StrEnum)`
a = "b"
A.a == "a" # OK
A.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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked mypy Playground reproduction using Python 3.12, strict equality, and the string enum whose member name differs from its value. Trace the comparison-overlap analysis for enum literals, then add or update a regression test so both comparisons produce no errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100