summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com>2022-01-15 13:43:20 +0000
committerJames Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com>2022-01-15 13:43:20 +0000
commit4b8bb7b3019db18726bcd5dbeac60e1897f3e9c0 (patch)
tree881539ba2663f482ef733ae4c0734b4436e1df64
parent596ad5523de2caa5b83a16bd61f99fca1a8d65b0 (diff)
downloadsphinx-git-4b8bb7b3019db18726bcd5dbeac60e1897f3e9c0.tar.gz
Only add returns section if there is something
-rw-r--r--sphinx/ext/napoleon/docstring.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index d8cb75a5f..5bfe88191 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]: