Repository navigation
docstring_parser: keep text that parsers dropped - #146
Merged
Merged
Conversation
When a docstring opens with its fields, the text found after them became a long description with no short one. `compose()` then wrote an empty first line, and parsing that back moved the text around. Read such text as if it had come before the fields: its first line is the short description and the rest the long one. This is the rule `_text.append_loose()` applies for every style that keeps loose text. `just parity` shows the change in 729 of 29,063 docstrings, all of them ReST or Numpydoc ones that start with a field.
An unindented line ends a Google section, so that unknown text is not read as the section's items (#29). That text, up to the next section, was then dropped: an example after `Args:`, a `Note:` or any title Google doesn't know, or the closing paragraph of a docstring. Add it to the long description instead, as ReST and Numpydoc do with text after their fields. `just parity` shows the change in 2,501 of 29,064 docstrings, all of them parsed as Google; 9 case files change, among them a pydantic docstring whose whole code example was lost.
Epydoc's fields are merged by the name they are about, so that a `@type` field finds its `@param`. A second description of the same name, such as `@param x:` followed by `@ivar x:`, or two `@return:` fields, overwrote the first, which was lost. Each description now gives an item of its own. A name's first item stays where its first field is, with its first description, so output only changes for names described more than once. `just parity` shows the change in 133 of 29,064 docstrings.
Check on every case file, in every style, that each word of the input is somewhere in the parse result, other than the titles and markers the style reads as syntax. Text that a parser drops, as Google did after a section and Epydoc did for a name described twice, fails it.
rr-
force-pushed
the
rework/8-keep-text
branch
from
November 6, 2026 10:39
e3a1e59 to
d84a2ba
Compare
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.
This PR fixes three ways parsers lost text, one commit each, and adds a test that catches the next one.
Args:, aNote:, a closing paragraph. It now goes to the long description, as ReST and Numpydoc already do with text after their fields. One pydantic docstring in the corpus had lost its whole code example.compose()started with an empty line. It's now read as if written before the fields.@param x:followed by@ivar x:, or two@return:fields, kept only the last description. Each description is its own item now.The new test checks on every case file, in every style, that each word of the input shows up somewhere in the parse result, apart from titles and markers the style reads as syntax.
just parityshows the changes in 729 (ReST/Numpydoc), 2,501 (Google) and 133 (Epydoc) docstrings. Speed is within 3% of main.