Skip to content

Commit 7716617

Browse files
authored
Move "Attributes" and "Methods" below "Parameters" (numpy#571)
1 parent 54dbc89 commit 7716617

File tree

4 files changed

+52
-23
lines changed

4 files changed

+52
-23
lines changed

numpydoc/docscrape.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ class NumpyDocString(Mapping):
120120
"Summary": [""],
121121
"Extended Summary": [],
122122
"Parameters": [],
123+
"Attributes": [],
124+
"Methods": [],
123125
"Returns": [],
124126
"Yields": [],
125127
"Receives": [],
128+
"Other Parameters": [],
126129
"Raises": [],
127130
"Warns": [],
128-
"Other Parameters": [],
129-
"Attributes": [],
130-
"Methods": [],
131+
"Warnings": [],
131132
"See Also": [],
132133
"Notes": [],
133-
"Warnings": [],
134134
"References": "",
135135
"Examples": "",
136136
"index": {},
@@ -549,8 +549,10 @@ def __str__(self, func_role=""):
549549
out += self._str_signature()
550550
out += self._str_summary()
551551
out += self._str_extended_summary()
552+
out += self._str_param_list("Parameters")
553+
for param_list in ("Attributes", "Methods"):
554+
out += self._str_param_list(param_list)
552555
for param_list in (
553-
"Parameters",
554556
"Returns",
555557
"Yields",
556558
"Receives",
@@ -563,8 +565,6 @@ def __str__(self, func_role=""):
563565
out += self._str_see_also(func_role)
564566
for s in ("Notes", "References", "Examples"):
565567
out += self._str_section(s)
566-
for param_list in ("Attributes", "Methods"):
567-
out += self._str_param_list(param_list)
568568
out += self._str_index()
569569
return "\n".join(out)
570570

numpydoc/docscrape_sphinx.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ def __str__(self, indent=0, func_role="obj"):
359359
"summary": self._str_summary(),
360360
"extended_summary": self._str_extended_summary(),
361361
"parameters": self._str_param_list("Parameters"),
362+
"attributes": (
363+
self._str_param_list("Attributes", fake_autosummary=True)
364+
if self.attributes_as_param_list
365+
else self._str_member_list("Attributes")
366+
),
367+
"methods": self._str_member_list("Methods"),
362368
"returns": self._str_returns("Returns"),
363369
"yields": self._str_returns("Yields"),
364370
"receives": self._str_returns("Receives"),
@@ -370,12 +376,6 @@ def __str__(self, indent=0, func_role="obj"):
370376
"notes": self._str_section("Notes"),
371377
"references": self._str_references(),
372378
"examples": self._str_examples(),
373-
"attributes": (
374-
self._str_param_list("Attributes", fake_autosummary=True)
375-
if self.attributes_as_param_list
376-
else self._str_member_list("Attributes")
377-
),
378-
"methods": self._str_member_list("Methods"),
379379
}
380380
ns = {k: "\n".join(v) for k, v in ns.items()}
381381

numpydoc/templates/numpydoc_docstring.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{{summary}}
33
{{extended_summary}}
44
{{parameters}}
5+
{{attributes}}
6+
{{methods}}
57
{{returns}}
68
{{yields}}
79
{{receives}}
@@ -13,5 +15,3 @@
1315
{{notes}}
1416
{{references}}
1517
{{examples}}
16-
{{attributes}}
17-
{{methods}}

numpydoc/tests/test_docscrape.py

+37-8
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,17 @@ def test_duplicate_signature():
12031203
b
12041204
c
12051205
1206+
Other Parameters
1207+
----------------
1208+
1209+
another parameter : str
1210+
This parameter is less important.
1211+
1212+
Notes
1213+
-----
1214+
1215+
Some notes about the class.
1216+
12061217
Examples
12071218
--------
12081219
For usage examples, see `ode`.
@@ -1223,10 +1234,6 @@ def test_class_members_doc():
12231234
jac : callable ``jac(t, y, *jac_args)``
12241235
Bbb.
12251236
1226-
Examples
1227-
--------
1228-
For usage examples, see `ode`.
1229-
12301237
Attributes
12311238
----------
12321239
t : float
@@ -1251,6 +1258,19 @@ def test_class_members_doc():
12511258
b
12521259
c
12531260
1261+
Other Parameters
1262+
----------------
1263+
another parameter : str
1264+
This parameter is less important.
1265+
1266+
Notes
1267+
-----
1268+
Some notes about the class.
1269+
1270+
Examples
1271+
--------
1272+
For usage examples, see `ode`.
1273+
12541274
""",
12551275
)
12561276

@@ -1304,10 +1324,6 @@ def no_period(self):
13041324
**jac** : callable ``jac(t, y, *jac_args)``
13051325
Bbb.
13061326
1307-
.. rubric:: Examples
1308-
1309-
For usage examples, see `ode`.
1310-
13111327
:Attributes:
13121328
13131329
**t** : float
@@ -1345,6 +1361,19 @@ def no_period(self):
13451361
**c**
13461362
===== ==========
13471363
1364+
:Other Parameters:
1365+
1366+
**another parameter** : str
1367+
This parameter is less important.
1368+
1369+
.. rubric:: Notes
1370+
1371+
Some notes about the class.
1372+
1373+
.. rubric:: Examples
1374+
1375+
For usage examples, see `ode`.
1376+
13481377
""",
13491378
)
13501379

0 commit comments

Comments
 (0)