Skip to content

Commit 22e5080

Browse files
authored
Merge pull request #65 from NelleV/64_section_twice
Raise an error when a section is present twice
2 parents 4835c31 + cb9c29d commit 22e5080

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
*.pyc
55
*.pyo
66
*.egg-info
7+
*.swp
8+
*.swo
79
build
810
dist

numpydoc/docscrape.py

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ def _parse(self):
327327
if not section.startswith('..'):
328328
section = (s.capitalize() for s in section.split(' '))
329329
section = ' '.join(section)
330+
if self.get(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

+16
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)