Repository navigation
Read the rest of napoleon's sections in Google and Numpydoc - #180
Merged
Merged
Conversation
Google read only params, raises, attributes, examples, returns and yields, and Numpydoc lacked Keyword Arguments, Methods, Todo and the admonitions. Both now read every section napoleon lists: - Keyword Args and Keyword Arguments, as keyword params - Other Parameters and Receive(s), in Google, as their params - Warns and Warn, in Google, as warnings raised - Raise, Return and Yield, in Google, as their plural - Note(s), Warning(s), See Also, References, Todo, Methods, Attention, Caution, Danger, Error, Hint, Important and Tip, as text - Deprecated, in Google, as a deprecation, with the version its body starts with, as in "1.2.0 Use other instead." A text section's meta keeps the section's title, which compose writes back. Compose gives keyword, other and received params and warnings sections of their own, so they read back as the kind they are. Compose indents a Google summary that reads as a title, such as "Note:", when a later line is unindented, as it was indented to be read as a summary. That makes one generated docstring round trip. Matching 40 titles with a group around each made Google parse 65% slower: a group keeps the regex engine from skipping an alternative at its first letter. Google now has one group for the title, and Numpydoc none for the titles that start their header, its title then being the first line of the match. Compose's nested functions take named annotations, which Python 3.8 evaluates at each definition.
With napoleon's sections the title regex has three times the alternatives, and matching in any case keeps the regex engine from skipping them by their first letter, so trying each at every line start made Google parsing about 10% slower than before on Python 3.14. Only a line that ends in a colon can hold a title, so find those lines first and match the title regex at their start alone. Parsers with bare titles or no title colon still search the whole text. In compose, look for a colon in the summary before taking its first line apart.
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.
Google and Numpydoc now recognise every section listed in the Sphinx napoleon docs:
Keyword Args/Keyword Argumentsare keyword params (Kind.KEYWORD), in both styles.Other ParametersandReceive/Receivesare other and received params.Warns/Warngive raises ofKind.WARNS.Raise,ReturnandYieldare read like their plural forms.titleset:Note(s),Warning(s),See Also,References,Todo,Methods,Attention,Caution,Danger,Error,Hint,ImportantandTip. Numpydoc already had the first four, and its text metas now carry theirtitleas well.Deprecated:gives aDocstringDeprecated. If the body starts with a version, that becomes the version:1.2.0 Use other instead.gives version1.2.0and descriptionUse other instead.Compose writes keyword, other and received params, and warns, into sections of their own. In Google they used to go under
Args:/Raises:, and in Numpydoc keyword params went underParameters, so they read back as the wrong kind. Google text sections are written under theirtitleand no longer under a name derived from the key. For example, see_also used to come out asSeealso:.Google compose also indents a summary that would otherwise read as a title, such as
Note:, when a later line is unindented. One generated docstring now round trips because of this, so(1856, GOOGLE)is removed fromGENERATED_EXCLUSIONS. No other exclusions changed.With roughly 40 titles in the regex, Google parse got 65% slower and Numpydoc 23% slower. The cause was a capture group around every title, which stops the regex engine from skipping an alternative after its first letter. Google now uses one group for the title. Numpydoc uses none for headers that begin with their title, and reads the title from the first line of the match. Compose's nested functions on 3.8 now use annotation aliases defined once at module level.
Thanks to @BrianPugh, whose #108 asked for several of these sections.
Case diffs
title:line on their text metas (Notes,See Also,Warnings, ...).convert/numpydoc-other-and-received-paramsandconvert/rest-params: other, received and keyword params are composed to Google underOther Parameters:,Receives:andKeyword Args:instead ofArgs:. Numpydoc puts keyword params underKeyword Arguments.corpus/pydantic/pydantic.fields.Field:Note:was long description and is now anotestext meta.corpus/numpy/..._NestedSequence: itsWarningheading keeps that title, so compose writesWarninginstead ofWarnings.google/napoleon_sections_01to_03,google/summary_title_01andnumpydoc/napoleon_sections_01.Parity against
origin/maintools/parity.pyalso reports 13 generated inputs that parse only in the tree.Most of the compose-only differences come from three things: the
titlethat compose now writes (See Also:instead ofSeealso:), the new keyword/other/received/warns sections, and the indented title-like summary when composing to Google from another style. The stdlib parse differences are docstrings where a line likeMethods:,References:,Notes:,Note:orExample:now starts a section. The three that parse only in base are argparse'sAction,FileTypeandArgumentParser: theirKeyword Arguments:items look like- prog -- text, which have no colon, so a Google parse now raisesParseErrorwhere it used to keep the text. Napoleon reads those the same way. Auto-detection still picks another style for them.Bench
Python 3.8, ratios between 0.76 and 1.06. The worst is Google parse at 1.06, mostly due to case-insensitive matching. Numpydoc parse is 0.84 and Google compose 0.78.
Not done
Deprecatedheading with an underline. Numpydoc already reads.. deprecated:: version, the numpydoc form, and aDeprecatedheading would clash with it once titles match in any case.Methodsis free text. Napoleon reads it asname: descriptionfields, but noKindexists for methods.