emit attribute/variable docstrings
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en el punto de entrada stubgen --include-docstrings y sigue cómo se recopilan y emiten actualmente los docstrings de módulos, clases y funciones. Incluye los docstrings de variables para variables a nivel de módulo, atributos de clase y de instancia, campos de dataclass y elementos de TypedDict; después, verifica que el ejemplo ResourceAttrs conserve la documentación de los campos en el .pyi generado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100