@@ -92,48 +92,15 @@ def __str__(self):
9292 return message
9393
9494
95- NUMPY_DOC_STRING_SECTIONS = {
96- 'Summary' ,
97- 'Extended' ,
98- 'Parameters' ,
99- 'Returns' ,
100- 'Yields' ,
101- 'Receives' ,
102- 'Other Parameters' ,
103- 'Raises' ,
104- 'Warns' ,
105- 'Warnings' ,
106- 'See Also' ,
107- 'Notes' ,
108- 'References' ,
109- 'Examples' ,
110- 'Attributes' ,
111- 'Methods' ,
112- }
113- '''Set of the strings corresponding to the sections outlined in numpydoc v1.8.0.''' ;
114-
115- CORE_NUMPY_DOC_STRING_SECTIONS = {
116- 'Summary' , 'Extended' , 'Parameters' , 'Returns' ,
117- }
118- '''The original four numpydoc sections supported by fastcore.''' ;
95+ SECTIONS = 'Summary Extended Yields Receives Other Raises Warns Warnings See Also Notes References Examples Attributes Methods' .split ()
11996
12097class NumpyDocString (Mapping ):
121- """Parses a numpydoc string to an abstract representation
122-
123- Notes
124- -----
125- See the NumPy Doc `Manual <https://numpydoc.readthedocs.io/en/latest/format.html>`_.
126- """
127- sections = {
128- 'Summary' : ['' ], 'Extended' : [],
129- 'Parameters' : [], 'Returns' : [],
130- 'Yields' : [], 'Receives' : [],
131- 'Other Parameters' : [], 'Raises' : [],
132- 'Warns' : [], 'Warnings' : [],
133- 'See Also' : [], 'Notes' : [],
134- 'References' : [], 'Examples' : [],
135- 'Attributes' : [], 'Methods' : [],
136- }
98+ "Parses a numpydoc string to an abstract representation"
99+ # See the NumPy Doc Manual https://numpydoc.readthedocs.io/en/latest/format.html>
100+ sections = {o :[] for o in SECTIONS }
101+ sections ['Summary' ] = ['' ]
102+ sections ['Parameters' ] = []
103+ sections ['Returns' ] = []
137104
138105 def __init__ (self , docstring , config = None ):
139106 docstring = textwrap .dedent (docstring ).split ('\n ' )
@@ -142,14 +109,7 @@ def __init__(self, docstring, config=None):
142109 self ._parse ()
143110 self ['Parameters' ] = {o .name :o for o in self ['Parameters' ]}
144111 if self ['Returns' ]: self ['Returns' ] = self ['Returns' ][0 ]
145- self ['Summary' ] = dedent_lines (self ['Summary' ], split = False )
146- self ['Extended' ] = dedent_lines (self ['Extended' ], split = False )
147- for section in NUMPY_DOC_STRING_SECTIONS ^ CORE_NUMPY_DOC_STRING_SECTIONS :
148- try :
149- self [section ] = dedent_lines (self [section ], split = False )
150- except Exception as err :
151- ...
152-
112+ for section in SECTIONS : self [section ] = dedent_lines (self [section ], split = False )
153113
154114 def __iter__ (self ): return iter (self ._parsed_data )
155115 def __len__ (self ): return len (self ._parsed_data )
0 commit comments