Skip to content

Commit

Permalink
Move "Attributes" and "Methods" below "Parameters" (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucascolley committed Jul 12, 2024
1 parent 54dbc89 commit 7716617
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
14 changes: 7 additions & 7 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions numpydoc/docscrape_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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()}

Expand Down
4 changes: 2 additions & 2 deletions numpydoc/templates/numpydoc_docstring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{{summary}}
{{extended_summary}}
{{parameters}}
{{attributes}}
{{methods}}
{{returns}}
{{yields}}
{{receives}}
Expand All @@ -13,5 +15,3 @@
{{notes}}
{{references}}
{{examples}}
{{attributes}}
{{methods}}
45 changes: 37 additions & 8 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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
Expand All @@ -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`.
""",
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`.
""",
)

Expand Down

0 comments on commit 7716617

Please sign in to comment.