Skip to content

Commit 1cbf2a3

Browse files
committed
refactor: Don't produce empty text section when parsing an empty Google-style docstring
1 parent 4ccc314 commit 1cbf2a3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/griffe/_internal/docstrings/google.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ def parse_google(
10411041

10421042
offset += 1
10431043

1044-
if current_section:
1044+
if current_section and any(current_section):
10451045
sections.append(DocstringSectionText("\n".join(current_section).rstrip("\n")))
10461046

10471047
if (

tests/test_docstrings/test_google.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,17 @@ def test_invalid_sections(parse_google: ParserType) -> None:
576576
assert not warnings
577577

578578

579+
def test_no_empty_text_section(parse_google: ParserType) -> None:
580+
"""Don't create a single empty text section for an empty docstring.
581+
582+
Parameters:
583+
parse_google: Fixture parser.
584+
"""
585+
sections, warnings = parse_google("")
586+
assert not sections
587+
assert not warnings
588+
589+
579590
# =============================================================================================
580591
# Parameters sections
581592
def test_parse_args_and_kwargs(parse_google: ParserType) -> None:

0 commit comments

Comments
 (0)