From e4514f221fd6566c98ce90a013915116e75cbcfe Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Mon, 8 Jul 2024 12:53:13 +0000 Subject: [PATCH 1/5] Move "Attributes" and "Methods" below "Parameters" --- numpydoc/docscrape.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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) From 8136de67a49833eb5b6de6c606820afdaf3aae86 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 11 Jul 2024 10:25:45 +0000 Subject: [PATCH 2/5] TST: test that Attributes comes after Parameters --- numpydoc/tests/test_docscrape.py | 47 ++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index a7f68c4e..e85220e8 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,21 @@ 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 +1326,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 +1363,19 @@ def no_period(self): **c** ===== ========== + .. rubric:: Other Parameters + + **another parameter** : str + This parameter is less important. + + .. rubric:: Notes + + Some notes about the class. + + .. rubric:: Examples + + For usage examples, see `ode`. + """, ) From 69473152dfaa1afec39088b7f85040f8c2a374f0 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Thu, 11 Jul 2024 10:41:29 +0000 Subject: [PATCH 3/5] fix `SphinxDocString` --- numpydoc/docscrape_sphinx.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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()} From b1e6c46b21462e176574625b00c71a4e413ee4d7 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Fri, 12 Jul 2024 12:38:45 +0000 Subject: [PATCH 4/5] update template --- numpydoc/templates/numpydoc_docstring.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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}} From d047745ea5f2d2adbdd5e1069ce83ce69416e60c Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Fri, 12 Jul 2024 13:09:08 +0000 Subject: [PATCH 5/5] fix tests --- numpydoc/tests/test_docscrape.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index e85220e8..4cafc762 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -1260,13 +1260,11 @@ def test_class_members_doc(): Other Parameters ---------------- - another parameter : str This parameter is less important. Notes ----- - Some notes about the class. Examples @@ -1363,10 +1361,10 @@ def no_period(self): **c** ===== ========== - .. rubric:: Other Parameters + :Other Parameters: - **another parameter** : str - This parameter is less important. + **another parameter** : str + This parameter is less important. .. rubric:: Notes