Add decorator to mark class as concrete / instantiable
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
We have the @final decorator to mark a class as final, so that it cannot be subclassed. Typecheckers can then cue off of this to raise an error when there are unimplemented abstract methods (e.g. the Ty abstract-method-in-final-class rule).
Similarly, Pyright and Ty can flag errors when other code instantiates a class that has abstract methods.
However, I would find it very useful to be able to mark a class as concrete: it isn't final (someone might subclass it), but it is intended to be instantiable. This would allow the type checker to raise abstract method errors at the point of class definition, rather than elsewhere in the code where the class is instantiated. For classes that are instantiated directly, the error location isn't a huge problem; for classes that are primarily instantiated indirectly, however, it there is no guarantee that the code will include a direct instantiation of the class to raise an error.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
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, den Vorschlag zusammen mit dem bestehenden @final-Dekorator und dem für Pyright und Ty beschriebenen Verhalten abstrakter Methoden zu prüfen. Lege die beabsichtigte Typprüfungssemantik des Dekorators für konkrete Klassen fest und bestätige, dass Fehler bei der Klassendefinition für Klassen mit abstrakten Methoden gemeldet werden, ohne die Klasse final zu machen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100