Repository navigation
Conversation
The last-resort split added in psf#5144 broke after every standalone comment leaf. A '# fmt: skip' on the opening bracket of an if/while/ for/with header turns 'if ( ... )' into a single standalone comment leaf that ends in ')', not a comment, so splitting after it put the ':' on its own line and Black failed on its own output. Only split after a standalone comment leaf whose last line has a comment in it. Fixes psf#5402 Co-Authored-By: Claude Opus 5 <[email protected]>
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 #5402.
The last-resort split added in #5144 (
_force_standalone_comment_split) breaks the line after every standalone comment leaf. With# fmt: skipon the opening bracket of a parenthesizedif/while/for/withheader, the wholeif ( ... )becomes a single standalone comment leaf whose text ends in), not in a comment. Splitting after it moved the:onto its own line, so Black failed on its own output:The fix only splits after a standalone comment leaf when its last line actually contains a comment, so the
:stays with the header. Real trailing comments still force the split as before.Added
fmtskip_compound_header_open_bracket.pycovering theif,while,forandwithforms from the issue. Full test suite passes locally (482 passed, 3 skipped).AI disclosure: this change was made with Claude Code under my supervision; I reviewed the fix and the test and ran the suite locally.
Checklist - did you ...
--previewstyle, following the stability policy? (crash fix, no style change)CHANGES.mdif necessary?🤖 Generated with Claude Code