Skip to content

Commit f13fc0a

Browse files
committed
fix: Numpy-style: don't strip spaces from the left of indented lines
Discussion #587: mkdocstrings/mkdocstrings#587
1 parent 15bdd74 commit f13fc0a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/griffe/docstrings/numpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _read_block_items(
129129

130130
if line.startswith(4 * " "):
131131
# continuation line
132-
current_item.append(line.lstrip())
132+
current_item.append(line[4:])
133133
previous_was_empty = False
134134

135135
elif line.startswith(" "):

tests/test_docstrings/test_numpy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,19 @@ def test_empty_indented_lines_in_section_with_items(parse_numpy: ParserType) ->
114114
assert len(sections2[0].value) == 2
115115

116116

117+
def test_doubly_indented_lines_in_section_items(parse_numpy: ParserType) -> None:
118+
"""In sections with items, don't remove all spaces on the left of indented lines.
119+
120+
Parameters:
121+
parse_numpy: Fixture parser.
122+
"""
123+
docstring = "Returns\n-------\nonly_item : type\n Description:\n\n - List item.\n - Sublist item."
124+
sections, _ = parse_numpy(docstring)
125+
assert len(sections) == 1
126+
lines = sections[0].value[0].description.split("\n")
127+
assert lines[-1].startswith(4 * " " + "- ")
128+
129+
117130
# =============================================================================================
118131
# Annotations
119132
def test_prefer_docstring_type_over_annotation(parse_numpy: ParserType) -> None:

0 commit comments

Comments
 (0)