summaryrefslogtreecommitdiff
path: root/sphinx/ext/napoleon
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-17 00:22:09 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-17 00:22:09 +0900
commit444dfc50aab740f9c658ea97b1f518dcac047d44 (patch)
tree27c69f87c24cb73e357eef5d830e27b7668b10d4 /sphinx/ext/napoleon
parent6a0215198fea5ec1dbda398aee8c64999baa0c0d (diff)
parentbd55cce6e6366804fb1dc5e516d11a98e00e4c46 (diff)
downloadsphinx-git-444dfc50aab740f9c658ea97b1f518dcac047d44.tar.gz
Merge branch '4.x'
Diffstat (limited to 'sphinx/ext/napoleon')
-rw-r--r--sphinx/ext/napoleon/__init__.py2
-rw-r--r--sphinx/ext/napoleon/docstring.py10
2 files changed, 5 insertions, 7 deletions
diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py
index a2fcb8c04..caf111fe3 100644
--- a/sphinx/ext/napoleon/__init__.py
+++ b/sphinx/ext/napoleon/__init__.py
@@ -288,7 +288,7 @@ class Config:
}
def __init__(self, **settings: Any) -> None:
- for name, (default, rebuild) in self._config_values.items():
+ for name, (default, _rebuild) in self._config_values.items():
setattr(self, name, default)
for name, value in settings.items():
setattr(self, name, value)
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]: