Skip to content

Commit 2855219

Browse files
committed
FIX raises an error if a section appears twice
closes numpy#64
1 parent 8dd78ec commit 2855219

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

numpydoc/docscrape.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,15 @@ def _parse(self):
323323
msg = 'Docstring contains both a Returns and Yields section.'
324324
raise ValueError(msg)
325325

326-
for (section, content) in sections:
326+
for (section, content) in sections:
327327
if not section.startswith('..'):
328328
section = (s.capitalize() for s in section.split(' '))
329329
section = ' '.join(section)
330+
if self[section]:
331+
msg = ("The section %s appears twice in the docstring." %
332+
section)
333+
raise ValueError(msg)
334+
330335
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
331336
'Warns', 'Other Parameters', 'Attributes',
332337
'Methods'):

numpydoc/tests/test_docscrape.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@ def test_returnyield():
209209
"""
210210
assert_raises(ValueError, NumpyDocString, doc_text)
211211

212+
213+
def test_section_twice():
214+
doc_text = """
215+
Test having a section Notes twice
216+
217+
Notes
218+
-----
219+
See the next note for more information
220+
221+
Notes
222+
-----
223+
That should break...
224+
"""
225+
assert_raises(ValueError, NumpyDocString, doc_text)
226+
227+
212228
def test_notes():
213229
assert doc['Notes'][0].startswith('Instead')
214230
assert doc['Notes'][-1].endswith('definite.')

0 commit comments

Comments
 (0)