Skip to content

Read ReST types with spaces in field heads - #164

Merged
rr- merged 1 commit into
mainfrom
rework/29-rest-spaced-types
Nov 6, 2026
Merged

rr- merged 1 commit into
mainfrom
rework/29-rest-spaced-types

Conversation

@rr-

@rr- rr- commented Nov 6, 2026

Copy link
Copy Markdown
Owner

A ReST field's head could hold at most a key, one type word and a name, so common real-world fields failed to parse:

:param Dict[str, int] x: The counts.
:raises ValueError, TypeError: If bad.

Before, parse() raised ParseError: Expected one or two arguments for a param keyword., and try_parse() reported wrong-arguments and kept the field as text. Now the first gives a param x with type Dict[str, int], and the second one raises with type ValueError, TypeError.

The words before the name make one type when they hold together: inside brackets (Callable[[int], str]), after a comma (int, optional), or around or, of and | (int or None, list of str). Other words in a row are still not a field, so :param with too many args: and :returns int str: keep raising, as before. This applies to every param-kind field (:param, :keyword, …), to raises fields, and to :returns/:yields. A single type word is read as before.

Composing writes such a type in its own :type x: or :rtype: field, which reads back the same, in all three renderings.

Parity: 0 of 29,123 docstrings differ (case, stdlib and generated), since none of them has a spaced type in a field head. Four new case files cover the new inputs and the one that still fails.

Bench on 3.8: parse is 0.99 to 1.00x of main.

@rr- rr- self-assigned this Nov 6, 2026
A field's head was split on spaces and had to be at most a key, a type
and a name, so :param Dict[str, int] x: and :raises A, B: raised
ParseError. The words before the name now make one type when they hold
together: inside brackets, after a comma, or around or, of and |.
Other words in a row, as in :param with too many args:, are still no
field.
@rr-
rr- force-pushed the rework/29-rest-spaced-types branch from e1f2783 to 1f23c42 Compare November 6, 2026 17:27
@rr-
rr- merged commit d611f47 into main Nov 6, 2026
25 checks passed
@rr-
rr- deleted the rework/29-rest-spaced-types 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