Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 8282604

Browse files
authored
fix: parse docstring that come without summaries (#187)
* fix: parse docstring with no summary given * test: update unit test for parsing docstring with no summary
1 parent 633606c commit 8282604

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

docfx_yaml/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ def _extract_docstring_info(summary_info, summary, name):
582582
# if we found empty array for indexes, stop processing further.
583583
index = min(indexes) if indexes else 0
584584

585-
# Store the top summary separately.
586-
if index == 0:
585+
# Store the top summary separately. Ensure that the docstring is not empty.
586+
if index == 0 and not indexes:
587587
return summary
588588

589589
top_summary = parsed_text[:index]

tests/test_unit.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,31 @@ def test_extract_docstring_info_with_xref(self):
431431
self.assertDictEqual(summary_info_got, summary_info_want)
432432

433433

434+
def test_extract_docstring_info_no_summary(self):
435+
## Test parsing docstring with no summary.
436+
summary =(
437+
"""Args:
438+
arg1(int): simple description.
439+
arg2(str): simple description for `arg2`.
440+
441+
Returns:
442+
str: simple description for return value.
443+
444+
Raises:
445+
AttributeError: if `condition x`.
446+
"""
447+
)
448+
summary_info_got = {
449+
'variables': {},
450+
'returns': [],
451+
'exceptions': []
452+
}
453+
454+
top_summary_got = _extract_docstring_info(summary_info_got, summary, "")
455+
self.assertEqual(top_summary_got, "")
456+
self.assertDictEqual(summary_info_got, self.summary_info1_want)
457+
458+
434459
def test_find_package_group(self):
435460
package_group_want = "google.cloud.spanner_v1beta2"
436461
uid = "google.cloud.spanner_v1beta2.services.admin_database_v1.types"

0 commit comments

Comments
 (0)