-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
Within an Enum
class e.g., SomeEnum
, elements initialized with auto()
and accessed as self.SOME_ELEMENT
have type enum.auto*
instead of SomeEnum
, resulting in false positives for comparison operations.
To Reproduce
Run mypy on the following code:
from enum import (
auto,
Enum,
)
class Game(Enum):
TENNIS = auto()
PING_PONG = auto()
SOCCER = auto()
def is_racquet_sport(self) -> bool:
return self in {self.TENNIS, self.PING_PONG}
# error: Non-overlapping container check (
# element type: "Game",
# container item type: "auto"
# )
# [comparison-overlap]
Expected Behavior
No errors should be issued.
Actual Behavior
A comparison-overlap
error is issued on the return
statement:
the_code_above.py:13: error: Non-overlapping container check (element type: "Game", container item type: "auto")
Found 1 error in 1 file (checked 1 source file)
Additional notes
Changing the element references from e.g. self.TENNIS
to Game.TENNIS
results in the expected behaviour.
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags:
--strict
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.8.12
- Operating system and version: macOS 10.14, homebrew 3.3.12, pyenv 2.2.3
frou, joshuafishman and smheidrich