-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed as duplicate of#10910
Closed as duplicate of#10910
Copy link
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
mypy
does not understand that in an Enum, self
can be compared to its members.
To Reproduce
from enum import Enum, auto
class Glass(Enum):
HALF_FULL = auto()
HALF_EMPTY = auto()
def print(self) -> str:
if self == self.HALF_FULL:
print("half full")
return
raise ValueError("Glass is not half-full.")
# prints "half full"
Glass.HALF_FULL.print()
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=edf65b45f562ed246f05592cc02f1fda
Expected Behavior
No error.
Actual Behavior
main.py:9: error: Non-overlapping equality check (left operand type: "Glass", right operand type: "auto") [comparison-overlap]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.10.0
- Mypy command-line flags:
--strict
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.12.3
#16327 seems related.
sk-caffeinatedgaze
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong