Skip to content

Commit

Permalink
Merge pull request #8713 from tk0miya/5560_napoleon_use_param_for_oth…
Browse files Browse the repository at this point in the history
…er_params

Close #5560: napoleon_use_param also affect "other parameters" section
  • Loading branch information
tk0miya committed Jan 21, 2021
2 parents a23781a + 73db152 commit 424510e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -16,6 +16,8 @@ Incompatible changes
MathJax configuration may have to set the old MathJax path or update their
configuration for version 3. See :mod:`sphinx.ext.mathjax`.
* #7784: i18n: The msgid for alt text of image is changed
* #5560: napoleon: :confval:`napoleon_use_param` also affect "other parameters"
section
* #7996: manpage: Make a section directory on build manpage by default (see
:confval:`man_make_section_directory`)
* #8380: html search: search results are wrapped with ``<p>`` instead of
Expand Down
8 changes: 7 additions & 1 deletion sphinx/ext/napoleon/docstring.py
Expand Up @@ -682,7 +682,13 @@ def _parse_notes_section(self, section: str) -> List[str]:
return self._parse_generic_section(_('Notes'), use_admonition)

def _parse_other_parameters_section(self, section: str) -> List[str]:
return self._format_fields(_('Other Parameters'), self._consume_fields())
if self._config.napoleon_use_param:
# Allow to declare multiple parameters at once (ex: x, y: int)
fields = self._consume_fields(multiple=True)
return self._format_docutils_params(fields)
else:
fields = self._consume_fields()
return self._format_fields(_('Other Parameters'), fields)

def _parse_parameters_section(self, section: str) -> List[str]:
if self._config.napoleon_use_param:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ext_napoleon_docstring.py
Expand Up @@ -1441,12 +1441,18 @@ def test_parameters_with_class_reference(self):
----------
param1 : :class:`MyClass <name.space.MyClass>` instance
Other Parameters
----------------
param2 : :class:`MyClass <name.space.MyClass>` instance
"""

config = Config(napoleon_use_param=False)
actual = str(NumpyDocstring(docstring, config))
expected = """\
:Parameters: **param1** (:class:`MyClass <name.space.MyClass>` instance)
:Other Parameters: **param2** (:class:`MyClass <name.space.MyClass>` instance)
"""
self.assertEqual(expected, actual)

Expand All @@ -1455,6 +1461,9 @@ def test_parameters_with_class_reference(self):
expected = """\
:param param1:
:type param1: :class:`MyClass <name.space.MyClass>` instance
:param param2:
:type param2: :class:`MyClass <name.space.MyClass>` instance
"""
self.assertEqual(expected, actual)

Expand Down

0 comments on commit 424510e

Please sign in to comment.