-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum elements accessed via 'self' have 'auto' type #12107
Comments
Note that the docs for the |
It seems that while this was the case in Python 3.10, since Python 3.11 there is no such recommendation anymore, and accessing members via other instances (including |
This bug also happens with literal values instead of import enum
class Planet(enum.Enum):
EARTH = 1
MARS = 2
JUPITER = 3
SATURN = 4
@property
def is_solid(self) -> bool:
return self in (self.EARTH, self.MARS)
@property
def is_home(self) -> bool:
return self is self.EARTH
home = Planet.EARTH
print(home)
print(home.MARS)
print(home.is_home)
print(home.is_solid) $ python3.8 teste.py
Planet.EARTH
Planet.MARS
True
True
$ mypy teste.py
teste.py:12: error: Non-overlapping container check (element type: "Planet", container item type: "int") [comparison-overlap]
teste.py:16: error: Non-overlapping identity check (left operand type: "Planet", right operand type: "Literal[1]") [comparison-overlap]
Found 2 errors in 1 file (checked 1 source file)
$ mypy --version
mypy 1.4.1 (compiled: yes) Btw, same errors if running as |
I believe this is a duplicate of #10910 |
Bug Report
Within an
Enum
class e.g.,SomeEnum
, elements initialized withauto()
and accessed asself.SOME_ELEMENT
have typeenum.auto*
instead ofSomeEnum
, resulting in false positives for comparison operations.To Reproduce
Run mypy on the following code:
Expected Behavior
No errors should be issued.
Actual Behavior
A
comparison-overlap
error is issued on thereturn
statement:Additional notes
Changing the element references from e.g.
self.TENNIS
toGame.TENNIS
results in the expected behaviour.Your Environment
--strict
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: