Skip to content

Commit

Permalink
fix: Numpy-style: don't strip spaces from the left of indented lines
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jul 10, 2023
1 parent 15bdd74 commit f13fc0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/griffe/docstrings/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _read_block_items(

if line.startswith(4 * " "):
# continuation line
current_item.append(line.lstrip())
current_item.append(line[4:])
previous_was_empty = False

elif line.startswith(" "):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_docstrings/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ def test_empty_indented_lines_in_section_with_items(parse_numpy: ParserType) ->
assert len(sections2[0].value) == 2


def test_doubly_indented_lines_in_section_items(parse_numpy: ParserType) -> None:
"""In sections with items, don't remove all spaces on the left of indented lines.
Parameters:
parse_numpy: Fixture parser.
"""
docstring = "Returns\n-------\nonly_item : type\n Description:\n\n - List item.\n - Sublist item."
sections, _ = parse_numpy(docstring)
assert len(sections) == 1
lines = sections[0].value[0].description.split("\n")
assert lines[-1].startswith(4 * " " + "- ")


# =============================================================================================
# Annotations
def test_prefer_docstring_type_over_annotation(parse_numpy: ParserType) -> None:
Expand Down

0 comments on commit f13fc0a

Please sign in to comment.