Skip to content

Commit fbe5336

Browse files
authored
Fix: Handle multi-line parameter definitions in GoogleParser (#98)
1 parent 80034b8 commit fbe5336

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/.gitignore
22
__pycache__
33
*.egg-info
4-
poetry.lock
4+
.idea/

docstring_parser/google.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta:
113113

114114
# Split spec and description
115115
before, desc = text.split(":", 1)
116+
117+
if before and "\n" in before:
118+
# If there is a newline in the first line, clean it up
119+
first_line, rest = before.split("\n", 1)
120+
before = first_line + inspect.cleandoc(rest)
121+
116122
if desc:
117123
desc = desc[1:] if desc[0] == " " else desc
118124
if "\n" in desc:

docstring_parser/tests/test_google.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ def test_google_parser_unknown_section() -> None:
2929
assert len(docstring.meta) == 0
3030

3131

32+
def test_google_parser_multi_line_parameter_type() -> None:
33+
"""Test parsing a multi-line parameter type with default GoogleParser"""
34+
parser = GoogleParser()
35+
docstring = parser.parse(
36+
"""Description of the function.
37+
38+
Args:
39+
output_type (Literal["searchResults", "sourcedAnswer",
40+
"structured"]): The type of output.
41+
This can be one of the following:
42+
- "searchResults": Represents the search results.
43+
- "sourcedAnswer": Represents a sourced answer.
44+
- "structured": Represents a structured output format.
45+
46+
Returns:
47+
bool: Indicates success or failure.
48+
49+
"""
50+
)
51+
assert docstring.params[0].arg_name == "output_type"
52+
53+
3254
def test_google_parser_custom_sections() -> None:
3355
"""Test parsing an unknown section with custom GoogleParser
3456
configuration.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ disable = [
7474
"too-many-branches",
7575
"too-many-statements",
7676
"too-many-arguments",
77+
"too-many-positional-arguments",
7778
"too-few-public-methods",
7879
"too-many-positional-arguments",
7980
]

0 commit comments

Comments
 (0)