Skip to content

docstring_parser: keep text that parsers dropped - #146

Merged
rr- merged 4 commits into
mainfrom
rework/8-keep-text
Nov 6, 2026
Merged

rr- merged 4 commits into
mainfrom
rework/8-keep-text

Conversation

@rr-

@rr- rr- commented Nov 6, 2026

Copy link
Copy Markdown
Owner

This PR fixes three ways parsers lost text, one commit each, and adds a test that catches the next one.

  • Google ended a section at an unindented line and dropped everything up to the next section: an example after Args:, a Note:, 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.
  • ReST and Numpydoc read text after the fields of a docstring with no description as a long description with no short one, so compose() started with an empty line. It's now read as if written before the fields.
  • Epydoc merges fields by name, so @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 parity shows the changes in 729 (ReST/Numpydoc), 2,501 (Google) and 133 (Epydoc) docstrings. Speed is within 3% of main.

@rr- rr- self-assigned this Nov 6, 2026
rr- added 4 commits November 6, 2026 11:39
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-
rr- force-pushed the rework/8-keep-text branch from e3a1e59 to d84a2ba Compare November 6, 2026 10:39
@rr-
rr- merged commit 3f5721e into main Nov 6, 2026
26 checks passed
@rr-
rr- deleted the rework/8-keep-text branch November 6, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant