-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
The elements of an enum are mistyped to their value by mypy if used within the same class.
from enum import Enum
class Letter(Enum):
A = 'A'
B = 'B'
@property
def shout(self) -> str:
s = {
self.A: 'Aaaaah',
self.B: 'Biiiih',
}
return s[self]
print(Letter.A.shout)
print(Letter.B.shout)
Using reveal_type
shows that self.A
is counted as a str
, while it isn't.
Expected Behavior
I guess a special handling for Enum subclasses that understands what's going on and types self.A
in a method of the class with the same type that Letter.A
has outside of the class.
Your Environment
- Mypy version used: 0.910
- Python version used: 3.9
- Operating system and version: debian sid