emit attribute/variable docstrings
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
stubgen --include-docstrings currently emits module, class, and function/method docstrings, but drops attribute (variable) docstrings — the string literal immediately following a variable assignment (PEP 224-style), which Pyright/Pylance read for hover and completion docs. I'd like --include-docstrings to also carry these through into the generated .pyi, for module-level variables, class/instance attributes, dataclass fields, and TypedDict items.
Pitch
minimal repro on mypy 2.1.0:
class ResourceAttrs(TypedDict, total=False):
"""Shared resource attributes."""
name: NotRequired[str]
"""Resource name."""
Actual: the field docstring is dropped; only the class docstring survives.
Expected: the """Resource name.""" line is preserved under name:.
Why it matters: attribute docstrings are the standard, tool-supported way to document TypedDict/dataclass/class fields; when a project ships a stub-only package built by stubgen, all per-field docs are silently lost even though the source has them. In my case, I am trying to build stubs for type completion on kwargs in an IDE like VS Code. I am trying to better document kwargs where they have been used historically, and with the full source code the IDE can tooltip the class property docstrings on hover (hover over the name key above shows "Resource name.", but this could be a more detailed docstring explaining the usage and impact of each keyword argument in the kwargs.
Workaround: class property documentation could be bubbled up into the class docstring, but this can be a bit more overwhelming as kwargs grows.
Context: this is the unfinished "members" part of #11965 (closed by #13284, which did module/class/function only). Related: #16114, #16543, #17200, #17964.
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 beim Einstiegspunkt stubgen --include-docstrings und verfolge, wie Modul-, Klassen- und Funktions-Docstrings derzeit gesammelt und ausgegeben werden. Berücksichtige Variablen-Docstrings für Variablen auf Modulebene, Klassen- und Instanzattribute, Dataclass-Felder und TypedDict-Elemente und überprüfe anschließend, dass das Beispiel ResourceAttrs die Feld-Dokumentation in der generierten .pyi beibehält.
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
- 55/100