Skip to content

Give items with no description None, never an empty string - #175

Merged
rr- merged 2 commits into
mainfrom
rework/45-none-descriptions
Nov 6, 2026
Merged

rr- merged 2 commits into
mainfrom
rework/45-none-descriptions

Conversation

@rr-

@rr- rr- commented Nov 6, 2026

Copy link
Copy Markdown
Owner

An item with no description now has None as its description in every style, never "". Before, an item with nothing after its colon got an empty string, while one with no colon at all got None. Users had to check for both.

Before:

>>> parse("Short.\n\n:param x:").params[0].description
''

After:

>>> parse("Short.\n\n:param x:").params[0].description is None
True

DocstringMeta and its subclasses store an empty description as None, so the parsers and items that users build give the same answer. Compose now writes each item so that it reads back with None:

  • A typed item with no description goes out as its type field alone, as a None one already did.
  • An untyped item, or one whose field carries its own type such as ReST :param int x:, keeps that field.
  • An Epydoc return with no type keeps its @return: field.
  • A Google raises type goes out alone unless it ends in a space. The colon after it keeps that space.

This is a breaking change: code that compares descriptions to "" has to compare to None now.

Parity against main: 3085 of 29157 docstrings differ (43 case, 40 stdlib, 3002 generated). Nearly all of them are parse output going from '' to None. The compose diffs are the field choices listed above. The round-trip invariant passes with no new exclusions.

Bench against main: 1.01x at most.

An item with nothing after its colon, such as ReST ":param x:", got an
empty string as its description, while one with no colon at all got
None. Every meta now takes None for an empty description, so users
test for one value only, in every style.

Compose loses the difference the two had, so it writes what reads back
as None: a typed item with no description as its type field alone, as
before for a None one; an untyped one, or one whose field gives its
own type, such as ReST ":param int x:", as its field; and a Google
raises type alone only when it has no trailing space, which the colon
after it keeps.
@rr- rr- self-assigned this Nov 6, 2026
@rr-
rr- merged commit 947fd77 into main Nov 6, 2026
26 checks passed
@rr-
rr- deleted the rework/45-none-descriptions 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