Skip to content

Commit c903e28

Browse files
committed
allow extending NumpyDocString sections
Current implementation of NumpyDocString define sections in `self._parsed_data` in `NumpyDocString.__init__()`, which is not convenient for developers to extend this class to add more sections. By setting section definitions as a class static variable, it will be more convenient for developers to extend more sections by changing the class static variable `sections`.
1 parent ef988a4 commit c903e28

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

numpydoc/docscrape.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,32 @@ def __str__(self):
9797

9898

9999
class NumpyDocString(collections.Mapping):
100+
sections = {
101+
'Signature': '',
102+
'Summary': [''],
103+
'Extended Summary': [],
104+
'Parameters': [],
105+
'Returns': [],
106+
'Yields': [],
107+
'Raises': [],
108+
'Warns': [],
109+
'Other Parameters': [],
110+
'Attributes': [],
111+
'Methods': [],
112+
'See Also': [],
113+
'Notes': [],
114+
'Warnings': [],
115+
'References': '',
116+
'Examples': '',
117+
'index': {}
118+
}
119+
100120
def __init__(self, docstring, config={}):
101121
orig_docstring = docstring
102122
docstring = textwrap.dedent(docstring).split('\n')
103123

104124
self._doc = Reader(docstring)
105-
self._parsed_data = {
106-
'Signature': '',
107-
'Summary': [''],
108-
'Extended Summary': [],
109-
'Parameters': [],
110-
'Returns': [],
111-
'Yields': [],
112-
'Raises': [],
113-
'Warns': [],
114-
'Other Parameters': [],
115-
'Attributes': [],
116-
'Methods': [],
117-
'See Also': [],
118-
'Notes': [],
119-
'Warnings': [],
120-
'References': '',
121-
'Examples': '',
122-
'index': {}
123-
}
125+
self._parsed_data = NumpyDocString.sections.copy()
124126

125127
try:
126128
self._parse()

0 commit comments

Comments
 (0)