From 21405613cb189deaafe033dbd5f61a905c60dd86 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Tue, 13 Sep 2016 09:55:42 -0700 Subject: [PATCH 1/3] FIX raises an error if a section appears twice closes #64 --- numpydoc/docscrape.py | 5 +++++ numpydoc/tests/test_docscrape.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index ed1760b0..3b65778d 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -327,6 +327,11 @@ def _parse(self): if not section.startswith('..'): section = (s.capitalize() for s in section.split(' ')) section = ' '.join(section) + if self[section]: + msg = ("The section %s appears twice in the docstring." % + section) + raise ValueError(msg) + if section in ('Parameters', 'Returns', 'Yields', 'Raises', 'Warns', 'Other Parameters', 'Attributes', 'Methods'): diff --git a/numpydoc/tests/test_docscrape.py b/numpydoc/tests/test_docscrape.py index 5b6a326e..3484ea2d 100644 --- a/numpydoc/tests/test_docscrape.py +++ b/numpydoc/tests/test_docscrape.py @@ -209,6 +209,22 @@ def test_returnyield(): """ assert_raises(ValueError, NumpyDocString, doc_text) + +def test_section_twice(): + doc_text = """ +Test having a section Notes twice + +Notes +----- +See the next note for more information + +Notes +----- +That should break... +""" + assert_raises(ValueError, NumpyDocString, doc_text) + + def test_notes(): assert doc['Notes'][0].startswith('Instead') assert doc['Notes'][-1].endswith('definite.') From c3e60b86bf6e493649d476ad5d5a60b557afaa02 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Tue, 13 Sep 2016 09:56:22 -0700 Subject: [PATCH 2/3] MAINT Added *.swp and *.swo to gitignore For vim users! --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 7f6f722f..81562fd2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,7 @@ *.pyc *.pyo *.egg-info +*.swp +*.swo build dist From cb9c29d9b42dfa852e8eb926111ecaefd6a393ee Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Mon, 19 Sep 2016 17:20:23 -0700 Subject: [PATCH 3/3] FIX Unknow sections should not raise an error --- numpydoc/docscrape.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpydoc/docscrape.py b/numpydoc/docscrape.py index 3b65778d..70c34293 100644 --- a/numpydoc/docscrape.py +++ b/numpydoc/docscrape.py @@ -327,7 +327,7 @@ def _parse(self): if not section.startswith('..'): section = (s.capitalize() for s in section.split(' ')) section = ' '.join(section) - if self[section]: + if self.get(section): msg = ("The section %s appears twice in the docstring." % section) raise ValueError(msg)