Skip to content

Commit fc098c4

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

File tree

2 files changed

+19
-56
lines changed

2 files changed

+19
-56
lines changed

numpydoc/docscrape.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,27 @@ def _parse(self):
347347
if not section.startswith('..'):
348348
section = (s.capitalize() for s in section.split(' '))
349349
section = ' '.join(section)
350-
if self.get(section):
351-
self._error_location("The section %s appears twice"
352-
% section)
353350

354351
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
355352
'Warns', 'Other Parameters', 'Attributes',
356353
'Methods'):
357-
self[section] = self._parse_param_list(content)
354+
existing_content = self.get(section, [])
355+
self[section] = (existing_content +
356+
self._parse_param_list(content))
357+
358358
elif section.startswith('.. index::'):
359359
self['index'] = self._parse_index(section, content)
360360
elif section == 'See Also':
361-
self['See Also'] = self._parse_see_also(content)
361+
existing_content = self.get('See Also', [])
362+
self['See Also'] = (existing_content +
363+
self._parse_see_also(content))
362364
else:
363-
self[section] = content
365+
existing_content = self.get(section, [])
366+
if existing_content:
367+
existing_content += ['']
368+
else:
369+
existing_content = []
370+
self[section] = existing_content + content
364371

365372
def _error_location(self, msg, error=True):
366373
if hasattr(self, '_obj'):

numpydoc/tests/test_docscrape.py

+6-50
Original file line numberDiff line numberDiff line change
@@ -241,59 +241,15 @@ def test_section_twice():
241241
242242
Notes
243243
-----
244-
That should break...
244+
That should merge
245245
"""
246-
assert_raises(ValueError, NumpyDocString, doc_text)
247-
248-
# if we have a numpydoc object, we know where the error came from
249-
class Dummy(object):
250-
"""
251-
Dummy class.
252-
253-
Notes
254-
-----
255-
First note.
256-
257-
Notes
258-
-----
259-
Second note.
260-
261-
"""
262-
def spam(self, a, b):
263-
"""Spam\n\nSpam spam."""
264-
pass
265-
266-
def ham(self, c, d):
267-
"""Cheese\n\nNo cheese."""
268-
pass
269-
270-
def dummy_func(arg):
271-
"""
272-
Dummy function.
273-
274-
Notes
275-
-----
276-
First note.
277-
278-
Notes
279-
-----
280-
Second note.
281-
"""
282-
283-
try:
284-
SphinxClassDoc(Dummy)
285-
except ValueError as e:
286-
# python 3 version or python 2 version
287-
assert_true("test_section_twice.<locals>.Dummy" in str(e)
288-
or 'test_docscrape.Dummy' in str(e))
289246

290-
try:
291-
SphinxFunctionDoc(dummy_func)
292-
except ValueError as e:
293-
# python 3 version or python 2 version
294-
assert_true("test_section_twice.<locals>.dummy_func" in str(e)
295-
or 'function dummy_func' in str(e))
247+
target = ['See the next note for more information',
248+
'',
249+
'That should merge']
296250

251+
doc = NumpyDocString(doc_text)
252+
assert doc['Notes'] == target
297253

298254
def test_notes():
299255
assert doc['Notes'][0].startswith('Instead')

0 commit comments

Comments
 (0)