Allow enum with zero members (rational provided)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
Just an option to bypass an error message and allow this:
class E(enum.IntEnum):
pass
E1: E
E2: E
E3: E
Pitch
Compared to this, it has the advantage below:
class E(enum.IntEnum):
E1 = ...
E2 = ...
E3 = ...
E1 = E.E1
E2 = E.E2
E3 = E.E3
When a Python API maps a C/C++ API, enum members are typically declared as int. But this is a pity, because it does not catch mixing of enum types. Also, when an enum match a C enum in an API, it is better if the class representing the type, does not have any member, because the members are aliased outside. Yes, one can write all enums instances are all of the same int type, but this is braking typing.
Also, there is an inconsistency, because in a loadable module, MyPy does not complain if an enum has no member. So why not allow it in stubs?
A practical case where the idea came to me, but I was sad to discover it does not work in stubs, while MyPy did not complain when I tried an enum with no members in a loadable module: https://github.com/AlexionSoftware/types-wxpython/issues/42#issuecomment-4962290300 . I prefer to wait for comments on this proposal, before editing the message linked, to say unfortunately it does not work, would prefer saying it just requires an option to be set.
Instead of a working clean idiom, I get this kind of error for each enum class declaration:
error: Detected enum "wx.StandardPaths.ResourceCat" in a type stub with zero members. There is a chance this is due to a recent change in the semantics of enum membership. If so, use
member = valueto mark an enum member, instead ofmember: type[misc]
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
Beginne damit, die gemeldete Diagnose für das Enum ohne Mitglieder in einem Type Stub zu reproduzieren, und vergleiche sie anschließend mit dem im Issue beschriebenen Fall eines ladbaren Moduls. Lies den Pfad zur Prüfung der Enum-Zugehörigkeit und die bestehende Fehlermeldung; als abgeschlossen gilt die Arbeit, wenn eine bewusst gesetzte Option die Stub-Form zulassen kann, ohne die gewöhnlichen Enum-Prüfungen abzuschwächen, mit Abdeckung für beide Fälle.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100