KEMBAR78
Type of an Enum nonmember is wrong when accessed through a member · Issue #19418 · python/mypy · GitHub
Skip to content

Type of an Enum nonmember is wrong when accessed through a member #19418

@cfriedland5

Description

@cfriedland5

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions