Repository navigation
Fix RST field list absorbing trailing blocks into last field (#86) - #113
Merged
rr- merged 1 commit intoOct 27, 2026
Merged
Conversation
A field ran until the next field or the end of the docstring, so a block after the field list, such as an example, became part of the last field's value. A blank line followed by unindented text that is not a field now ends the field, also with CRLF line endings, and that text goes to the long description instead of being dropped. Fixes rr-#86.
rr-
force-pushed
the
fix/issue-86-rst-field-list-boundary
branch
from
October 27, 2026 22:16
f81ee06 to
8e4d5ee
Compare
Owner
|
Thanks @apoorvdarshan! I force-pushed to your branch to rebase it onto master and reword the commit to the repo's new commit-message format. I also made two fixes:
I added tests for both. You're still the commit author and credited in the changelog. CI is green, so I'm merging this now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #86
Root cause
In the ReST parser (
docstring_parser/rest.py), the field list is split into individual fields with:A field only ends at the next line starting with
:or at the end of input. Any trailing block that follows the field list but has no leading:(e.g. anExamplesection after:rtype: dict) therefore gets pulled into the value of the last field. The last:rtype:/:param:type then swallows everything after it.Reproduction
Wrong output (before the fix):
Corrected output (after the fix):
Fix
Terminate a field not only at the next
:field:or end of input, but also at a blank line followed by unindented, non-field content — which is where an RST field list ends:r"(^:.*?)(?=^:|\n[ \t]*\n(?=[^ \t\n:])|\Z)"The new alternative
\n[ \t]*\n(?=[^ \t\n:])matches a blank line followed by a line that starts at the base indentation and is not another field, so the trailing block is no longer absorbed. This is deliberately narrow:Tests
Added
test_returns_does_not_absorb_trailing_blockindocstring_parser/tests/test_rest.py, which asserts that a:rtype: dictfollowed by a trailingExampleblock yieldstype_name == "dict". The test fails on the unmodified code (the type name includes the whole Example block) and passes with the fix.The full existing test suite passes (255 passed).
black,isort, andpylint(repo config) are clean on the changed files.Disclosure: prepared with AI assistance; reviewed and verified locally.