python / python/mypy

emit attribute/variable docstrings

Ouverte
#21,645 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

feature topic-stubgen
Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Métriques de merge des PR
Métriques de PR en attente

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par le point d’entrée stubgen --include-docstrings et suivez la manière dont les docstrings de module, de classe et de fonction sont actuellement collectés et émis. Couvrez les docstrings de variables pour les variables au niveau du module, les attributs de classe et d’instance, les champs de dataclass et les éléments de TypedDict, puis vérifiez que l’exemple ResourceAttrs conserve la documentation des champs dans le .pyi généré.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
tooling
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.