Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- General: Compose docstrings so they parse back the same
- General: Unescape names in every style, such as `\*\*kwargs` or `class\_`
- General: Make each run of whitespace in a type one space
- General: Clean attribute docstrings in `parse_from_object()` as other docstrings
- ReST: Stop the last field from absorbing text after the field list (thanks to @apoorvdarshan)
- ReST: Raise `ParseError`, not `IndexError`, for a field with no name
- ReST: Indent compact continuation lines so a leading role isn't read as a field
Expand Down
4 changes: 3 additions & 1 deletion docstring_parser/attrdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import typing as T
from types import ModuleType

from ._lines import cleandoc
from .common import Docstring, DocstringParam, Kind


Expand Down Expand Up @@ -120,7 +121,8 @@ def add_attribute_docstrings(
if arg_name not in documented:
param = DocstringParam(
key="attribute",
description=description,
# Cleaned as a docstring is, without its indent.
description=cleandoc(description) if description else None,
arg_name=arg_name,
type_name=type_name,
is_optional=default is not None,
Expand Down
16 changes: 16 additions & 0 deletions docstring_parser/tests/test_parse_from_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,19 @@ def test_from_object_with_descriptor_doc() -> None:

assert docstring.short_description is None
assert len(docstring.meta) == 0


def test_attribute_docstring_is_cleaned() -> None:
"""Test that an attribute's docstring is cleaned as a docstring is."""

class WithAttr:
"""Class docstring."""

value: int = 1
"""
Indented
attribute doc.
"""

docstring = parse_from_object(WithAttr)
assert docstring.attrs[0].description == "Indented\n attribute doc."
Loading