python / python/mypy

Marking a private `Enum` member as `member()` does not work

Open
#18,563 3 comments 0 reactions 1 assignee View on GitHub

@sobolevn is already working on this.

Since Jan 29, 2025.

bug topic-enum
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Consider this example:

from enum import Enum, member

class Pet(Enum):
    __CAT = member(1)

reveal_type(Pet.__CAT)  # N: Revealed type is "enum.member[Literal[1]?]"

Link: https://mypy-play.net/?mypy=latest&python=3.12&gist=63b056215c22ba7ff09e2559dd2ae08a

However, in runtimes it fails with AttributeError, because __CAT is mangled to _Pet__CAT as regular private names are.

We need to fix this corner-case.

Refs https://github.com/python/mypy/issues/18491
Refs https://github.com/python/mypy/issues/18557

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.