summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-16 02:40:58 +0900
committerGitHub <noreply@github.com>2022-01-16 02:40:58 +0900
commit542db8ffb668f470e131b373e7d244cb3d966af6 (patch)
tree61d2b3e48464f8e120e34424f184da41791dea79
parenta55a765e797197cfdf8a3e5033efe8ed72191a62 (diff)
parentff2105a2f3cea9e0997b26a1416582c01b5b4c74 (diff)
downloadsphinx-git-542db8ffb668f470e131b373e7d244cb3d966af6.tar.gz
Merge pull request #10101 from Gobot1234/4.x
Fix empty returns section
-rw-r--r--sphinx/ext/napoleon/docstring.py10
-rw-r--r--tests/test_ext_napoleon_docstring.py12
2 files changed, 16 insertions, 6 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 96cb5be85..d1d348590 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -769,12 +769,9 @@ class GoogleDocstring:
def _parse_returns_section(self, section: str) -> List[str]:
fields = self._consume_returns_section()
multi = len(fields) > 1
- if multi:
- use_rtype = False
- else:
- use_rtype = self._config.napoleon_use_rtype
-
+ use_rtype = False if multi else self._config.napoleon_use_rtype
lines: List[str] = []
+
for _name, _type, _desc in fields:
if use_rtype:
field = self._format_field(_name, '', _desc)
@@ -787,7 +784,8 @@ class GoogleDocstring:
else:
lines.extend(self._format_block(':returns: * ', field))
else:
- lines.extend(self._format_block(':returns: ', field))
+ if any(field): # only add :returns: if there's something to say
+ lines.extend(self._format_block(':returns: ', field))
if _type and use_rtype:
lines.extend([':rtype: %s' % _type, ''])
if lines and lines[-1]:
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index b47f6d6d3..f0399a894 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -267,6 +267,18 @@ class GoogleDocstringTest(BaseDocstringTest):
"""
Single line summary
+ Returns:
+ Extended
+ """,
+ """
+ Single line summary
+
+ :returns: Extended
+ """
+ ), (
+ """
+ Single line summary
+
Args:
arg1(str):Extended
description of arg1