Repository navigation
Fix crash on two # fmt: skip statements in a row - #5626
Open
LuisFigueroaG wants to merge 3 commits into
Open
LuisFigueroaG wants to merge 3 commits into
LuisFigueroaG wants to merge 3 commits into
Conversation
cobaltt7
reviewed
Oct 26, 2026
| is outside the selected `--line-ranges` (#5549) | ||
| - Fix crash when a compound statement header with `# fmt: skip` contains a bracket that | ||
| has its own `# fmt: skip` on the opening line (#5597, #5612, #5610) | ||
| has its own `# fmt: skip` on the opening line (#5597, #5612, #5610, #5626) |
Collaborator
There was a problem hiding this comment.
This change is not as accurately described by this changelog entry as the others. You can check if there's a different changelog entry that fits well or make a new one (just please try to keep it concise and avoid internal details)
Contributor
Author
There was a problem hiding this comment.
Thanks, I gave it its own entry under Stable style instead.
This branch has not been deployed
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
Two statements in a row that each have
# fmt: skipinside a bracket crash Black:fails with "INTERNAL ERROR: Black produced invalid code: cannot parse: 2:1" because the output is
)bar(b # fmt: skip. The same happens when the second statement is awith,if,for,class, decorator orreturnwhose first line is hidden, e.g.x = ( # fmt: skip...)followed bywith ( # fmt: skip...):. This is a regression from #5610 and isn't in a release yet: 26.10.1 formats these fine.#5610 keeps hidden code on the line where the previous hidden code ends when there is no newline in its prefix, for two
# fmt: skipbrackets in one statement. But the newline between two statements isn't in the prefix of the second one, it's in theNEWLINEtoken of the first. When# fmt: skiphides a whole statement, that token is hidden with it too, so nothing separates the two hidden parts anymore. And when the second statement is a compound statement, its keyword is hidden, sovisit_stmtdoesn't start a new line before it._continues_fmt_skip_linenow also checks that the hidden code doesn't start a statement. Hidden code that continues the previous one's line always comes after something in the same statement, like theifof a conditional expression, or the;it hides along with the next statement.I checked ~18k generated combinations of two or three statements (with brackets hidden in different ways, one-liners,
;,# fmt: off, comments and blank lines, at module level and in a function) in stable, preview and unstable. Wherevermaindoesn't crash, the output is the same with this branch, and none of them crash now.Checklist - did you ...
--previewstyle, following the stability policy?CHANGES.mdif necessary?