Skip to content

Commit 542db8f

Browse files
authored
Merge pull request #10101 from Gobot1234/4.x
Fix empty returns section
2 parents a55a765 + ff2105a commit 542db8f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

sphinx/ext/napoleon/docstring.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,9 @@ def _parse_references_section(self, section: str) -> List[str]:
769769
def _parse_returns_section(self, section: str) -> List[str]:
770770
fields = self._consume_returns_section()
771771
multi = len(fields) > 1
772-
if multi:
773-
use_rtype = False
774-
else:
775-
use_rtype = self._config.napoleon_use_rtype
776-
772+
use_rtype = False if multi else self._config.napoleon_use_rtype
777773
lines: List[str] = []
774+
778775
for _name, _type, _desc in fields:
779776
if use_rtype:
780777
field = self._format_field(_name, '', _desc)
@@ -787,7 +784,8 @@ def _parse_returns_section(self, section: str) -> List[str]:
787784
else:
788785
lines.extend(self._format_block(':returns: * ', field))
789786
else:
790-
lines.extend(self._format_block(':returns: ', field))
787+
if any(field): # only add :returns: if there's something to say
788+
lines.extend(self._format_block(':returns: ', field))
791789
if _type and use_rtype:
792790
lines.extend([':rtype: %s' % _type, ''])
793791
if lines and lines[-1]:

tests/test_ext_napoleon_docstring.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ class GoogleDocstringTest(BaseDocstringTest):
267267
"""
268268
Single line summary
269269
270+
Returns:
271+
Extended
272+
""",
273+
"""
274+
Single line summary
275+
276+
:returns: Extended
277+
"""
278+
), (
279+
"""
280+
Single line summary
281+
270282
Args:
271283
arg1(str):Extended
272284
description of arg1

0 commit comments

Comments
 (0)