You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Enum members have a field set in the Enum's __init__ method, mypy exhaustiveness checking incorrectly considers that field to be a member of the Enum, and therefore a possible value.
All members of the enum are represented in match cases, so the exhaustiveness check should pass. I expect no mypy errors.
Actual Behavior
main.py:22: error: Argument 1 to "assert_never" has incompatible type "Literal[Planet.mass, Planet.radius]"; expected "NoReturn" [arg-type]
Found 1 error in 1 file (checked 1 source file)
Planet.mass is not an enum member, so Literal[Planet.mass] is not a possible type for p. In fact, evaluating Planet.mass raises AttributeError. Only an expression like Planet.EARTH.mass is allowed. Same for radius.
Your Environment
Mypy version used: 1.8.0
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.12
The text was updated successfully, but these errors were encountered:
Bug Report
When Enum members have a field set in the Enum's
__init__
method, mypy exhaustiveness checking incorrectly considers that field to be a member of the Enum, and therefore a possible value.To Reproduce
Using the Planet example from the enum documentation:
https://mypy-play.net/?mypy=1.8.0&python=3.12&gist=8efc534dda9e5cb62e4ff9f7aff7f5e6
Expected Behavior
All members of the enum are represented in match cases, so the exhaustiveness check should pass. I expect no mypy errors.
Actual Behavior
Planet.mass
is not an enum member, soLiteral[Planet.mass]
is not a possible type forp
. In fact, evaluatingPlanet.mass
raises AttributeError. Only an expression likePlanet.EARTH.mass
is allowed. Same forradius
.Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: