Open
Description
Bug Report
Accessing an instance of an enum though another instance leads to the wrong type being inferred for the instance.
To Reproduce
import enum
class Color(enum.Enum):
RED = "RED"
GREEN = "GREEN"
BLUE = "BLUE"
c = Color.RED
# error: Incompatible types in assignment (expression has type "str", variable has type "Color") [assignment]
c = c.GREEN
Expected Behavior
I expect mypy to understand that c.GREEN
is also of type Color
.
Actual Behavior
Mypy thinks c.GREEN
is of type str
.
main.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "Color") [assignment]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: master (post 1.3.0 at time of writing)
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini
(and other config files): n/a - Python version used: 3.12