Skip to content

Read deprecated directives in ReST and Google - #169

Merged
rr- merged 3 commits into
mainfrom
rework/39-deprecated-directive
Nov 6, 2026
Merged

rr- merged 3 commits into
mainfrom
rework/39-deprecated-directive

Conversation

@rr-

@rr- rr- commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

ReST and Google now read a .. deprecated:: directive in the free text as a DocstringDeprecated, as Numpydoc already did, and Epydoc reads @deprecated as one too. The version comes from the directive line and the indented body is the description. Each directive gives its own item, and the directive leaves the long description.

>>> d = parse("Short.\n\n.. deprecated:: 1.0\n    Use other().\n", "rest")
>>> d.deprecation.version, d.deprecation.description
('1.0', 'Use other().')

Before, the directive stayed in the long description in ReST and Google, and Epydoc's @deprecated was a plain text meta.

Compose writes deprecations back as directives in ReST and Google, and keeps the version in Epydoc. Before, ReST wrote a :deprecation: field that dropped the version, and Google wrote a Deprecation: section that read back as text.

The round-trip test on main passes with no new exclusions.

Parity: 1,989 of 29,162 docstrings differ: 28 case, 0 stdlib, 1,961 generated. Every one has a deprecated directive or field in its input.

@rr- rr- self-assigned this Nov 6, 2026
rr- added 2 commits November 6, 2026 21:45
A ".. deprecated:: <version>" directive in the free text now gives a
DocstringDeprecated in ReST and Google, as it does in Numpydoc: the
version from its line, its indented body as the description. The
directive leaves the description, and every directive gives an item.
A directive on the first line of text is read whatever its indent, as
the short description it would otherwise give is.

The cutting of directives out of the lines moves from ReST's attribute
directives into _directives, which both parsers use, with the placing
of a leading deprecation after the short description that Numpydoc
compose did on its own. ReST and Google compose a deprecation as the
directive: right after the short description when it comes first, or
else in its place among the items. A blank line around it is written
only where it reads back the same. ReST keeps a :deprecated: field for
a deprecation read from one with a description.

Epydoc reads @deprecated as a deprecation, with the version that starts
its description, and composes a deprecation as that field with its
version.
Composing a docstring looked for a deprecation to write as a directive
at its start and end, which made composing ReST 22% slower. Look only
when the first or last meta is a deprecation.
@rr-
rr- force-pushed the rework/39-deprecated-directive branch from cfe56e1 to 4266940 Compare November 6, 2026 20:55
Composing a Google docstring looked for a deprecation to write after
the short description every time, which took composing to the edge of
10% slower. Look only when the first meta is a deprecation.
@rr-
rr- merged commit 5a89e46 into main Nov 6, 2026
26 checks passed
@rr-
rr- deleted the rework/39-deprecated-directive 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