Skip to content

End Numpydoc sections at undeclared headings - #166

Merged
rr- merged 1 commit into
mainfrom
rework/27-numpydoc-headings
Nov 6, 2026
Merged

rr- merged 1 commit into
mainfrom
rework/27-numpydoc-headings

Conversation

@rr-

@rr- rr- commented Nov 6, 2026

Copy link
Copy Markdown
Owner

After the first section, Numpydoc read an underlined heading that no section declares as items of the section before it. A lowercase See also after Returns, which numpy itself writes in places, came out as three fake returns:

Returns
-------
inds : tuple of arrays
    The row and column indices.
See also
--------
triu_indices : similar function, for upper-triangular.

Before: returns inds, See also, -------- and triu_indices. Now: the return inds, then a text meta with key see_also, title See also and the section's text as its description.

The rule:

  • After the first declared section, an unindented line underlined by as many dashes as it has characters ends the section before it, as a declared title does.
  • The heading becomes a text meta. Its key is the title in snake case (Custom Title gives custom_title), and the new DocstringMeta.title keeps the title as written, so compose writes it back and the docstring round-trips.
  • Headings inside an Examples section stay in it, since doctest output may hold a table whose header row looks underlined, as in numpy.einsum_path.
  • Headings before the first declared section stay in the description, as before.

Matching titles regardless of case, and underlines shorter than the title, are separate changes.

Parity against main: 13 of 29,127 docstrings differ, and each has an undeclared heading after a section.

  • 5 corpus cases: See also in numpy.can_cast and numpy.tril_indices, Options in scipy.optimize._minimize_powell, and Methods in two scipy classes.
  • 2 new cases.
  • 6 generated docstrings. In 2 of them auto-detection now picks Numpydoc over ReST, since Numpydoc reads more of them.
  • No stdlib docstring changes.

Bench on 3.8: Numpydoc parse is 1.04x of main, with and without sections, and everything else is 0.98–1.01x.

@rr- rr- self-assigned this Nov 6, 2026
After the first section, an underlined heading that no section declares,
such as "See also" or "Options", was read as items of the section before
it: the title, its dashes and its text became fake returns or params.
Such a heading now ends the section and becomes a text meta, keyed by
its title in snake case, with the title kept in the new title field so
compose writes it back.

Headings in an examples section stay there, since doctest output may
hold a table whose header row looks underlined. Headings before the
first section stay in the description, as before.
@rr-
rr- force-pushed the rework/27-numpydoc-headings branch from 3298f57 to 573f65f Compare November 6, 2026 17:33
@rr-
rr- merged commit 24246b0 into main Nov 6, 2026
25 checks passed
@rr-
rr- deleted the rework/27-numpydoc-headings branch November 6, 2026 23:51
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