Support functional API for Enum *Subclasses* too
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Tested with version 0.641.
The functional API for enums is only supported on Enum itself, and not subclasses (that do not override the relevant methods). I hit this using the OrderedEnum suggestion from the standard library documentation: https://docs.python.org/3/library/enum.html#orderedenum.
Running on:
from enum import Enum
class Foo(Enum):
""
Bar: type = Enum('Bar', ['X', 'Y']) # line 6
Baz: type = Foo('Baz', ['X', 'Y']) # line 7
bar: Bar = Bar.X # line 9
baz: Baz = Baz.Y # line 10
gives
asdf.py:7: error: Incompatible types in assignment (expression has type "Foo", variable has type "type")
asdf.py:7: error: Too many arguments for "Foo"
asdf.py:10: error: Invalid type "asdf.Baz"
asdf.py:10: error: "type" has no attribute "Y"
Note that 6 is deemed fine, but 7 causes complaints. I'd hope for both lines to be fine.
The even larger issue is that annotations using Baz totally fail too: Line 9 is deemed fine but 10 fails. I wouldn't mind the obscure use of the Enum subclass failing if it weren't for the fact that every annotation with my nice enum type won't work.
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 mit dem Reproducer im Issue und verfolge, wie mypy die funktionale API von Enum für Enum-Unterklassen verarbeitet. Prüfe, wie der abgeleitete Typ von Foo('Baz', ['X', 'Y']) und Annotationen, die Baz verwenden, verarbeitet werden. Als abgeschlossen gilt die Aufgabe, wenn sowohl der Factory-Aufruf der Unterklasse als auch Mitglieder vom Typ Baz ohne die gemeldeten Fehler typgeprüft werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100