Skip to content

Commit 71d2a30

Browse files
committed
ENH: merge duplicate sections (rather than raise)
This allows the docs for matplotlib 1.5.x to continue building.
1 parent 24e915e commit 71d2a30

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

numpydoc/docscrape.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,27 @@ def _parse(self):
330330
if not section.startswith('..'):
331331
section = (s.capitalize() for s in section.split(' '))
332332
section = ' '.join(section)
333-
if self.get(section):
334-
msg = ("The section %s appears twice in the docstring." %
335-
section)
336-
raise ValueError(msg)
337333

338334
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
339335
'Warns', 'Other Parameters', 'Attributes',
340336
'Methods'):
341-
self[section] = self._parse_param_list(content)
337+
existing_content = self.get(section, [])
338+
self[section] = (existing_content +
339+
self._parse_param_list(content))
340+
342341
elif section.startswith('.. index::'):
343342
self['index'] = self._parse_index(section, content)
344343
elif section == 'See Also':
345-
self['See Also'] = self._parse_see_also(content)
344+
existing_content = self.get('See Also', [])
345+
self['See Also'] = (existing_content +
346+
self._parse_see_also(content))
346347
else:
347-
self[section] = content
348+
existing_content = self.get(section, [])
349+
if existing_content:
350+
existing_content += ['']
351+
else:
352+
existing_content = []
353+
self[section] = existing_content + content
348354

349355
# string conversion routines
350356

numpydoc/tests/test_docscrape.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,15 @@ def test_section_twice():
220220
221221
Notes
222222
-----
223-
That should break...
223+
That should merge
224224
"""
225-
assert_raises(ValueError, NumpyDocString, doc_text)
226225

226+
target = ['See the next note for more information',
227+
'',
228+
'That should merge']
229+
230+
doc = NumpyDocString(doc_text)
231+
assert doc['Notes'] == target
227232

228233
def test_notes():
229234
assert doc['Notes'][0].startswith('Instead')

0 commit comments

Comments
 (0)