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.
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.