-
-
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
fix: Consider space-only lines to be empty #220
Conversation
Whoops, I think I left my comment directly on the commit, rather than the PR 🤷♂️ I think checking for And then the |
You're right, but I think the previous order of conditions was not handling both cases correctly, and now it is. Previously:
Now:
Single blank lines are still supported in the middle of parameter descriptions. EDIT: or maybe not... I'll add tests to confirm. |
Seems like there's a single issue: docstring = """
Examples
--------
Line 1.
Line 2.
"""
sections, _ = parse_numpy(docstring, allow_section_blank_line=False)
assert len(sections) == 2 This fails. |
It seems like this won't be routed to right place, since |
I'm not sure what you mean in the last comment. And I'm not sure my own comment was clear 😅 I'll try to restate things more clearly. IMO it looks like the
...and Then, in parameter descriptions (or any other kind of item, like raised exceptions or emitted warnings), the option is currently "baked-in": whatever its value, a single blank line does not break the item or section, and two blank lines break the item and section. I'd say this behavior makes sense, but this can be debated. I don't see why anyone would use two blank lines instead of one if they don't want to break a section... unless they use Markdown extensions that insert dynamic contents in the docstring, with unchecked leading/trailing new lines? (For sections themselves, I previously decided it should break with a single blank line by default to retain the previous behavior, for backward compatibility) Maybe the Damn, that sounds so complicated for a single docstring parser 😅 IMO we just have to fix the failing case, and we're good to go. |
As far as I know, the notion of ending a section based on linebreaks only applies to certain contexts in the parser:
ExamplesSince
Since
The change
I could be very wrong here!I've tried to read through the git blame for the parser to get a feel for the original behavior, but I could be missing something 😅. Overall, though, I think the PR may be implementing new, more aggressive terminating of sections, and with numpydoc empty lines are often not meant to signal that a section is ending. Thanks for taking the time read through all this, and improve the numpy parser! I'm happy to dig deeper where useful! |
Thanks for the feedback. It all makes sense. It guess it boils down to: do we want to allow prose in between sections? Which the Numpydoc style guide does not explicitly allow. If not, then we don't have to check for blank lines anywhere, since our only section delimiters are sections titles (and the dash line after them). However I'm strong on "line with spaces only is an empty/blank line", because linters will report these lines, and formatters will remove the spaces, and therefore users shouldn't have to rely on those. This fits well with "no prose in-between sections" anyway. Should we move towards this? |
Hey, sorry for the wait -- I tried out a bunch of docstrings in sphinx, and also afaict it also doesn't care if you have a line that's just 4 spaces. Let me test a little bit more, but I think I'm coming around to...
|
How are your tests going 🙂? |
Related to PR #219: #219
@machow