Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raises an error when a section is present twice #65

Merged
merged 3 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
*.pyc
*.pyo
*.egg-info
*.swp
*.swo
build
dist
5 changes: 5 additions & 0 deletions numpydoc/docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.get(section)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would that be better? If section is not a key of the dictionary (nor starts with ..), an error will be raise later on (l.344). But maybe I am missing something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont want keyerror here for unknown sections

14.9.2016 0.07 "Nelle Varoquaux" notifications@github.com kirjoitti:

In numpydoc/docscrape.py
#65 (comment):

@@ -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]:
    

Why would that be better? If section is not a key of the dictionary (nor
starts with ..), an error will be raise later on (l.344). But maybe I am
missing something.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/numpy/numpydoc/pull/65/files/c3e60b86bf6e493649d476ad5d5a60b557afaa02#r78653691,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACI5h84FYPNrWGYb-dMfi3ciFvrIIpsks5qpx59gaJpZM4J76JG
.

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'):
Expand Down
16 changes: 16 additions & 0 deletions numpydoc/tests/test_docscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down