Skip to content

Keep yields apart from returns - #156

Merged
rr- merged 1 commit into
mainfrom
rework/18-yields
Nov 6, 2026
Merged

rr- merged 1 commit into
mainfrom
rework/18-yields

Conversation

@rr-

@rr- rr- commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Returns and yields both parse into DocstringReturns, and Docstring.returns took the first DocstringReturns it found. A generator's docstring then looked like it documented a return value:

>>> docstring = parse("Short.\n\nYields:\n    int: The next number.")
>>> docstring.returns.description   # before
'The next number.'
>>> docstring.returns               # now
None
>>> docstring.yields.description
'The next number.'

returns and many_returns now leave out metas whose kind is Kind.YIELDS. The new yields and many_yields give those instead. The class stays DocstringReturns and is_generator stays, so code that reads yields through meta keeps working.

This is breaking for users who read yields through returns. They need to switch to yields. pydoclint's fork has yields and many_yields under these names, so code written against the fork works with this.

Parse output does not change, so parity is 0 of 29,074. The change is only in what the two properties return. A yield shows up in some style for 9 case inputs, 4 stdlib docstrings and 2,454 generated ones, and those are the docstrings where returns can now give something else.

Bench on 3.8: 0.99–1.03x of main.

@rr- rr- self-assigned this Nov 6, 2026
Docstring.returns and many_returns gave yields too, as they share the
DocstringReturns class, so a generator's docstring looked like it
documented a return value. They now leave out metas of kind YIELDS,
which the new yields and many_yields give instead.
@rr-
rr- force-pushed the rework/18-yields branch from 1408f86 to 20dc961 Compare November 6, 2026 16:33
@rr-
rr- merged commit 72d53d8 into main Nov 6, 2026
24 of 25 checks passed
@rr-
rr- deleted the rework/18-yields 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