From 7716617eac1f61c6b0563781ea5f3a3cf7301d93 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Fri, 12 Jul 2024 15:49:46 +0100 Subject: [PATCH] Move "Attributes" and "Methods" below "Parameters" (#571) --- numpydoc/docscrape.py | 14 +++---- numpydoc/docscrape_sphinx.py | 12 +++--- numpydoc/templates/numpydoc_docstring.rst | 4 +- numpydoc/tests/test_docscrape.py | 45 +++++++++++++++++++---- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index f3b4a0ce..aa13217e 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -120,17 +120,17 @@ class NumpyDocString(Mapping): "Summary": [""], "Extended Summary": [], "Parameters": [], + "Attributes": [], + "Methods": [], "Returns": [], "Yields": [], "Receives": [], + "Other Parameters": [], "Raises": [], "Warns": [], - "Other Parameters": [], - "Attributes": [], - "Methods": [], + "Warnings": [], "See Also": [], "Notes": [], - "Warnings": [], "References": "", "Examples": "", "index": {}, @@ -549,8 +549,10 @@ def __str__(self, func_role=""): out += self._str_signature() out += self._str_summary() out += self._str_extended_summary() + out += self._str_param_list("Parameters") + for param_list in ("Attributes", "Methods"): + out += self._str_param_list(param_list) for param_list in ( - "Parameters", "Returns", "Yields", "Receives", @@ -563,8 +565,6 @@ def __str__(self, func_role=""): out += self._str_see_also(func_role) for s in ("Notes", "References", "Examples"): out += self._str_section(s) - for param_list in ("Attributes", "Methods"): - out += self._str_param_list(param_list) out += self._str_index() return "\n".join(out) diff --git a/numpydoc/docscrape_sphinx.py b/numpydoc/docscrape_sphinx.py index ed389fb4..9b1ccf78 100644 --- a/numpydoc/docscrape_sphinx.py +++ b/numpydoc/docscrape_sphinx.py @@ -359,6 +359,12 @@ def __str__(self, indent=0, func_role="obj"): "summary": self._str_summary(), "extended_summary": self._str_extended_summary(), "parameters": self._str_param_list("Parameters"), + "attributes": ( + self._str_param_list("Attributes", fake_autosummary=True) + if self.attributes_as_param_list + else self._str_member_list("Attributes") + ), + "methods": self._str_member_list("Methods"), "returns": self._str_returns("Returns"), "yields": self._str_returns("Yields"), "receives": self._str_returns("Receives"), @@ -370,12 +376,6 @@ def __str__(self, indent=0, func_role="obj"): "notes": self._str_section("Notes"), "references": self._str_references(), "examples": self._str_examples(), - "attributes": ( - self._str_param_list("Attributes", fake_autosummary=True) - if self.attributes_as_param_list - else self._str_member_list("Attributes") - ), - "methods": self._str_member_list("Methods"), } ns = {k: "\n".join(v) for k, v in ns.items()} diff --git a/numpydoc/templates/numpydoc_docstring.rst b/numpydoc/templates/numpydoc_docstring.rst index 79ab1f8e..f6b6a0ae 100644 --- a/numpydoc/templates/numpydoc_docstring.rst +++ b/numpydoc/templates/numpydoc_docstring.rst @@ -2,6 +2,8 @@ {{summary}} {{extended_summary}} {{parameters}} +{{attributes}} +{{methods}} {{returns}} {{yields}} {{receives}} @@ -13,5 +15,3 @@ {{notes}} {{references}} {{examples}} -{{attributes}} -{{methods}} diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index a7f68c4e..4cafc762 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -1203,6 +1203,17 @@ def test_duplicate_signature(): b c + Other Parameters + ---------------- + + another parameter : str + This parameter is less important. + + Notes + ----- + + Some notes about the class. + Examples -------- For usage examples, see `ode`. @@ -1223,10 +1234,6 @@ def test_class_members_doc(): jac : callable ``jac(t, y, *jac_args)`` Bbb. - Examples - -------- - For usage examples, see `ode`. - Attributes ---------- t : float @@ -1251,6 +1258,19 @@ def test_class_members_doc(): b c + Other Parameters + ---------------- + another parameter : str + This parameter is less important. + + Notes + ----- + Some notes about the class. + + Examples + -------- + For usage examples, see `ode`. + """, ) @@ -1304,10 +1324,6 @@ def no_period(self): **jac** : callable ``jac(t, y, *jac_args)`` Bbb. - .. rubric:: Examples - - For usage examples, see `ode`. - :Attributes: **t** : float @@ -1345,6 +1361,19 @@ def no_period(self): **c** ===== ========== + :Other Parameters: + + **another parameter** : str + This parameter is less important. + + .. rubric:: Notes + + Some notes about the class. + + .. rubric:: Examples + + For usage examples, see `ode`. + """, )