`AbstractContextManger.__enter__` should be abstract
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
Code sample in basedpyright playground
from contextlib import AbstractContextManager
from typing import override
class CM(AbstractContextManager[int]):
@override
def __exit__(self, *_): ...
with CM() as i:
print(i + 1)
AbstractContextManger.__enter__ has a default implementation that returns self, so by making it abstract you would require implementations to provide the correct implementation. this would force a redundant implementation if the type is Self, but that is currently impossible to type anyway: https://discuss.python.org/t/self-as-typevar-default/90939
even without Self support, it is only one line of redundant code: def __enter__(self) -> Self: return self
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 basedpyright playground example und dem AbstractContextManager stub entry point, den es ausführt. Prüfe, wie sich das aktuelle standardmäßige enter auf die Prüfung abstrakter Klassen auswirkt, und verifiziere anschließend, dass eine Abstrakterklärung eine Implementierung erfordert, während das beabsichtigte Typisierungsverhalten von Context-Managern erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 55/100