-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
If you add a class variable to an enum using enum.nonmember and then access that variable through a member instead of the class, the type is nonmember[T] instead of just T. Accessing the variable through the class produces the expected result.
To Reproduce
https://mypy-play.net/?mypy=latest&python=3.13&gist=5472648e0c1a970b9f5424612864eb3a
from enum import Enum, auto, nonmember
class Foo(Enum):
BAR = auto()
baz = nonmember("A")
def fun(x: str) -> None:
raise NotImplementedError
fun(Foo.baz) # No error, works as expected
fun(Foo.BAR.baz) # error: Argument 1 to "fun" has incompatible type "nonmember[str]"; expected "str" [arg-type]Expected Behavior
Mypy should think that the type of Foo.BAR.baz is str (or even better, Literal["A"])
Actual Behavior
Mypy thinks that the type of Foo.BAR.baz is nonmember[str]
Your Environment
- Mypy version used: 1.16.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.13