Fix numpy docstring args being misparsed as section headers (fixes #439)#686
Open
UditDewan wants to merge 1 commit into
Open
Fix numpy docstring args being misparsed as section headers (fixes #439)#686UditDewan wants to merge 1 commit into
UditDewan wants to merge 1 commit into
Conversation
In a numpy-style Parameters section, an argument whose name matches a
section title keyword (e.g. "argument", "param", "key") was
misinterpreted as the start of a new Google-style Args section. The
argument was then dropped from the parsed docstring and its description
was appended to the previous argument, producing misaligned help text.
Numpy parameter lines have whitespace before the colon ("argument :
int"), while Google section headers do not ("Args:"), so treat such
lines inside a numpy section as parameters rather than section headers.
Fixes google#439
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #439
Problem
With a numpy-style docstring, an argument whose name happens to match a section title keyword (
argument,arg,param,parameter,key, ...) breaks help text alignment:--helppreviously showed both descriptions underEXECUTABLEand nothing underARGUMENT:Cause
Inside the numpy
Parameterssection, the lineargument :sits at the same indentation as the section header, so_google_section_permittedallows it to start a new section, and_google_sectionmatchesargumentagainst the Args section titles. The parser switches to a Google-style Args section, so the argument is never recorded and the following description line is appended to the previous argument.Fix
Numpy parameter lines have whitespace before the colon (
argument : int), while Google section headers do not (Args:). When the parser is inside a numpy-format section, a line whose colon is preceded by whitespace is now treated as a parameter definition rather than a new section header.With the fix,
--helpshows:Added a regression test using the example from the issue. All existing docstring and helptext tests pass.