Repository navigation
sections: declare sections alike in every style - #144
Merged
Merged
Conversation
Add `docstring_parser.sections` with `SectionSpec`, which gives a section's titles, the kind of its items, their key and their layout. The same spec works in every style: its titles are section titles in Google and Numpydoc, and field names in ReST and Epydoc. A list of specs goes to `parse()`, `parse_from_object()`, each style module's `parse()`, `GoogleParser` and `NumpydocParser` as `sections`, and `default_sections(style)` gives the ones a style uses by default. A spec's kind decides its items' kind and class, so a section no longer has to be keyed `param` to give params. `bare=True` takes a title alone on its line, with no colon or underline. `parse_item` gets each item's meta, already split, to change it or replace it. ReST's and Epydoc's fields become tables of specs, and Google's and Numpydoc's builders go by the kind of their section instead of by its key. Epydoc's five header regexes become one and a check of how many names each kind of field takes, which keeps every error and quirk. The ways to customise parsing by overriding keep working. Passing a style's default sections gives the same output as passing none on every case file, and `just parity` finds no difference without sections.
This was referenced Nov 7, 2026
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 adds
docstring_parser.sectionswithSectionSpec, one way to declare sections for all four styles.A spec gives a section's titles, the kind of its items, their key and their layout. In Google and Numpydoc the titles are section titles; in ReST and Epydoc they are field names. A list goes to
parse(),parse_from_object(), each style module'sparse(),GoogleParserandNumpydocParserassections.default_sections(style)returns a style's own list to build on.paramto give params.bare=Truetakes a title alone on its line, with no colon (Google) or underline (Numpydoc).parse_itemgets each item's meta, already split, to change or replace it.Under the hood, ReST and Epydoc fields become tables of specs, and Google and Numpydoc builders go by the section's kind instead of its key. Epydoc's five header regexes become one, with every error and quirk kept; Epydoc parses in about 0.65 of the time on main.
The README has a section on it. The old ways to customise parsing (overriding
titles_re,title_pattern,_build_meta,_parse_item,KV_REGEX) keep working; the next PR removes them.No output change: passing a style's default sections gives the same result as passing none on every case file, and
just parityfinds no difference. The other styles stay within 3% of main.