Open
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