Skip to content

Commit

Permalink
ENH: merge duplicate sections (rather than raise)
Browse files Browse the repository at this point in the history
This allows the docs for matplotlib 1.5.x to continue building.
  • Loading branch information
tacaswell committed Nov 2, 2017
1 parent 5b1169f commit fc098c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 56 deletions.
19 changes: 13 additions & 6 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,27 @@ def _parse(self):
if not section.startswith('..'):
section = (s.capitalize() for s in section.split(' '))
section = ' '.join(section)
if self.get(section):
self._error_location("The section %s appears twice"
% section)

if section in ('Parameters', 'Returns', 'Yields', 'Raises',
'Warns', 'Other Parameters', 'Attributes',
'Methods'):
self[section] = self._parse_param_list(content)
existing_content = self.get(section, [])
self[section] = (existing_content +
self._parse_param_list(content))

elif section.startswith('.. index::'):
self['index'] = self._parse_index(section, content)
elif section == 'See Also':
self['See Also'] = self._parse_see_also(content)
existing_content = self.get('See Also', [])
self['See Also'] = (existing_content +
self._parse_see_also(content))
else:
self[section] = content
existing_content = self.get(section, [])
if existing_content:
existing_content += ['']
else:
existing_content = []
self[section] = existing_content + content

def _error_location(self, msg, error=True):
if hasattr(self, '_obj'):
Expand Down
56 changes: 6 additions & 50 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,59 +241,15 @@ def test_section_twice():
Notes
-----
That should break...
That should merge
"""
assert_raises(ValueError, NumpyDocString, doc_text)

# if we have a numpydoc object, we know where the error came from
class Dummy(object):
"""
Dummy class.
Notes
-----
First note.
Notes
-----
Second note.
"""
def spam(self, a, b):
"""Spam\n\nSpam spam."""
pass

def ham(self, c, d):
"""Cheese\n\nNo cheese."""
pass

def dummy_func(arg):
"""
Dummy function.
Notes
-----
First note.
Notes
-----
Second note.
"""

try:
SphinxClassDoc(Dummy)
except ValueError as e:
# python 3 version or python 2 version
assert_true("test_section_twice.<locals>.Dummy" in str(e)
or 'test_docscrape.Dummy' in str(e))

try:
SphinxFunctionDoc(dummy_func)
except ValueError as e:
# python 3 version or python 2 version
assert_true("test_section_twice.<locals>.dummy_func" in str(e)
or 'function dummy_func' in str(e))
target = ['See the next note for more information',
'',
'That should merge']

doc = NumpyDocString(doc_text)
assert doc['Notes'] == target

def test_notes():
assert doc['Notes'][0].startswith('Instead')
Expand Down

0 comments on commit fc098c4

Please sign in to comment.