From 73db152cf65d090ef433db9acd49107ffd21aba3 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 20 Jan 2021 23:21:11 +0900 Subject: [PATCH] Close #5560: napoleon_use_param also affect "other parameters" section --- CHANGES | 2 ++ sphinx/ext/napoleon/docstring.py | 8 +++++++- tests/test_ext_napoleon_docstring.py | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d55f3dc8cd6..f9844e53b6f 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ``

`` instead of diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index 755088ca576..a5a986e4980 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -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: diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index ec5f90ac201..4ee66aaa5df 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1441,12 +1441,18 @@ def test_parameters_with_class_reference(self): ---------- param1 : :class:`MyClass ` instance +Other Parameters +---------------- +param2 : :class:`MyClass ` instance + """ config = Config(napoleon_use_param=False) actual = str(NumpyDocstring(docstring, config)) expected = """\ :Parameters: **param1** (:class:`MyClass ` instance) + +:Other Parameters: **param2** (:class:`MyClass ` instance) """ self.assertEqual(expected, actual) @@ -1455,6 +1461,9 @@ def test_parameters_with_class_reference(self): expected = """\ :param param1: :type param1: :class:`MyClass ` instance + +:param param2: +:type param2: :class:`MyClass ` instance """ self.assertEqual(expected, actual)