Preserve function docstring spacing with line ranges - #5286
Draft
happykawayigt wants to merge 2 commits into
Draft
Preserve function docstring spacing with line ranges#5286happykawayigt wants to merge 2 commits into
happykawayigt wants to merge 2 commits into
Conversation
happykawayigt
force-pushed
the
fix/line-range-docstring-blank
branch
from
August 3, 2026 12:13
38f5d7b to
8542127
Compare
Collaborator
|
Is there a reason this is a draft PR? It all looks good to me! |
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.
Description
Fixes #5285.
When line-range formatting replaces out-of-range code with
fmt: passplaceholders, those placeholders are represented as comment lines. The blank-line tracker could therefore scan past the enclosing function boundary and misclassify its docstring as a module docstring, adding a blank line that was outside the requested formatting range.Treating a converted
fmt: passline as a scope boundary preserves the existing spacing. The regression fixture exercises every single-line range across a formatted function whose docstring has no following blank line.Validation:
pytest tests/test_format.py -q(230 passed)git diff --checkAI assistance was used during implementation. I independently reviewed the line-range conversion path and final diff, reproduced the regression through the line-by-line fixture, and ran the validation above.
Checklist - did you ...
--previewstyle, following the stability policy? (No style change.)CHANGES.mdif necessary?