Skip to content

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

Closed

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

Activity

  1. added a commit that references this issue on Aug 3, 2025
  2. added a commit that references this issue on Aug 3, 2025
    9d3a052
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions