-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
feat: numpy admonitions #219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks a lot!
I wanted to make sure that this is compatible with the allow_section_blank_line
option, and upon looking at the only test (!) above that checks this option, test_empty_indented_lines_in_section_with_items
, it seems to me that the option works incorrectly: lines that are only composed of spaces should be considered empty lines, and therefore the mentioned test should fail in the second part (assert len(sections2) == 1
) because there are 3 empty lines between the last line of the returns section and the next non-empty line.
I'd suggest to remove that second part from the test_empty_indented_lines_in_section_with_items
test, which is not meant to check blank lines, and to add some tests similar to the ones you added in this PR that make sure allow_section_blank_line
works as expected. If it doesn't, we can fix it in another PR.
My reasoning about empty lines: if we consider a line with spaces only to be non-empty, users could start relying on this behavior to prevent breaking a section by keeping one or more spaces on an otherwise empty line. But formatters will probably not allow it: I think Black now removes spaces from such lines. This would clash with the perceived feature that we support non-section-breaking lines. Also users could be surprised that when both allowing or disallowing blank lines, their section do not break because of some white space that are difficult to spot. Therefore I think we should consider lines with just spaces to be empty, to avoid any ambiguity.
The current, wrong behavior probably comes from this:
if line.startswith(4 * " "):
...
elif line.startswith(" "):
...
elif _is_empty_line(line):
We should probably check first if the line is empty?
The Google parser has the same conditions so it probably suffers from the same issue.
I'll send a PR to fix both parsers 🙂
UPDATE: actually the Google parser relies on indentation so the issue was mitigated. I'll still fix the order of conditions for good measure.
…ions on blank lines Breaking change: This change removes the docstring option `allow_section_blank_line` for the Numpydoc parser, and changes the parsing logic so that blank lines are now *always* allowed, in any number, between sections. Sections are now only delimited by section headers themselves. The result of these changes is that: **prose is not allowed in between Numpydoc sections anymore**, making the parser compliant with the Numpydoc style guide and its maintainers recommendations. PR #220: #220 Related to PR #219: #219 Numpydoc discussion: numpy/numpydoc#463
I tried to refactor the flow a bit, to make it easier to follow. Let me know what you think if you have time. I'll probably merge tomorrow in any case 🙂 |
This PR addresses #214, by parsing all unknown numpydoc sections as admonitions.
I'm not totally clear on the similarity / differences between numpydoc and google style docstrings, but hopefully this makes their parsed representations a bit closer to each other.
I think one big difference is that, a well-specified numpydoc docstring is made up of two things:
However, there's one more rule:
Here's my attempt to represent when DocstringSectionText, DocstringSectionAdmonition, and more defined sections like DocstringSectionParameters will appear.
Happy to tweak, enhance! Would love your thoughts on whether this seems to capture what DocstringSectionAdmonition is meant for. I tried to use the google docstring code as a reference..!