From fc098c4423a4141fbe228b6916b3ad0050cbd330 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 16 Oct 2016 13:25:24 -0400 Subject: [PATCH 1/2] ENH: merge duplicate sections (rather than raise) This allows the docs for matplotlib 1.5.x to continue building. --- numpydoc/docscrape.py | 19 +++++++---- numpydoc/tests/test_docscrape.py | 56 ++++---------------------------- 2 files changed, 19 insertions(+), 56 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 6ca62922..ab3e458a 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -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'): diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 8fa3d23f..957eb7d4 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -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..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..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') From ed9f5e63c2a36d0c0ca3e62634a8474519b3873a Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 16 Oct 2016 13:38:04 -0400 Subject: [PATCH 2/2] MNT: correct default type from References/Examples The default value was a string, if there is input these will be filled as lists. --- numpydoc/docscrape.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index ab3e458a..1f03cf0d 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -128,8 +128,8 @@ class NumpyDocString(collections.Mapping): 'See Also': [], 'Notes': [], 'Warnings': [], - 'References': '', - 'Examples': '', + 'References': [], + 'Examples': [], 'index': {} } @@ -365,8 +365,6 @@ def _parse(self): 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):