Enum `_ignore_`'d names and private names are treated like normal members
Open
Nobody has claimed this yet.
bug
topic-enum
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
To Reproduce
from enum import Enum
from typing import TYPE_CHECKING
class Foo(Enum):
__str__ = lambda self: "blah"
_ignore_ = ["ignored"]
ignored = lambda _: "blah"
_Foo__private = lambda _: "blah"
print(Foo.__members__) # {}
print(Foo.__str__) # <function Foo.<lambda> at 0x...>
if TYPE_CHECKING:
reveal_type(Foo.__str__) # note: Revealed type is "def () -> builtins.str" ✅
print(hasattr(Foo, "_ignore_")) # False
if TYPE_CHECKING:
reveal_type(Foo._ignore_) # error: "type[Foo]" has no attribute "_ignore_" [attr-defined] ✅
print(hasattr(Foo, "ignored")) # False
if TYPE_CHECKING:
reveal_type(Foo.ignored) # note: Revealed type is "Literal[__main__.Foo.ignored]?" ❌
print(Foo._Foo__private) # <function Foo.<lambda> at 0x...>
if TYPE_CHECKING:
reveal_type(Foo._Foo__private) # note: Revealed type is "Literal[__main__.Foo._Foo__private]?" ❌
https://mypy-play.net/?mypy=latest&python=3.13&gist=ea296898a9c0e29c550b6154fb2cb594
Actual Behavior
main.py:16: note: Revealed type is "def () -> builtins.str"
main.py:20: error: "type[Foo]" has no attribute "_ignore_" [attr-defined]
main.py:20: note: Revealed type is "Any"
main.py:24: note: Revealed type is "Literal[__main__.Foo.ignored]?"
main.py:28: note: Revealed type is "Literal[__main__.Foo._Foo__private]?"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.14.1
- Python version used: 3.13
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example with mypy 1.14.1 on Python 3.13, focusing on Enum handling of str, ignore, ignored, and the name-mangled private member. Trace the type-checking path that classifies Enum attributes and add regression coverage so ignored and private names are not treated as normal members.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100