Enum `_ignore_`'d names and private names are treated like normal members
Offen
Dieses Issue hat noch niemand übernommen.
bug
topic-enum
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Beispiel mit mypy 1.14.1 unter Python 3.13, mit Fokus auf der Behandlung von str, ignore, ignored und dem durch Namensmangling erzeugten privaten Member durch Enum. Verfolge den Type-Checking-Pfad, der Enum-Attribute klassifiziert, und füge Regressionstests hinzu, damit ignorierte und private Namen nicht als normale Member behandelt werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100