Repository navigation
Closed
Labels
formatterRelated to the Ruff formatterRelated to the Ruff formatterhelp wantedContributions especially welcomeContributions especially welcomestyleHow should Ruff-formatted code lookHow should Ruff-formatted code look
Description
From Black's changelog and Preview enum. Last checked 19.09.2025, Last release: v25.9.0.
Goals:
- Close parity with Black when migrating from Black to Ruff
- Fix Ruff specific bugs
- Innovate on local formatting (to keep close parity with black)
Preview Styles
Stabilized in Black and not available in Ruff (even in preview)
-
remove_lone_list_item_parens - Allow newlines after block open (or not) #9745 -- progress towards this here Allow newlines after function headers without docstrings #21110
Black preview styles
-
wrap_long_dict_values_in_parensNon-goal, see Preview style feedback: Parenthesizing long dict, conditional, and type annotations psf/black#4123 and Nested expression formatting #12856 -
always_one_newline_after_importThis is enforced by unsorted-imports (I001) and configurable vialines-after-imports. There is already some small conflict with the formatter depending on how the user configures this, and this may cause a little more. Unsure about this one... -
fix_fmt_skip_in_one_linersRespectfmt: skipfor compound statements on single line #20633 Respectfmt: skipfor multiple statements on same logical line #22119 -
wrap_comprehension_in -
remove_parens_around_except_types -
normalize_cr_newlinesAlready handled by Ruff Ruff 2026 Style Guide #20482 (comment)
Black unstable styles
-
string_processingNon-goal, various issues https://github.com/psf/black/issues?q=is%3Aissue%20state%3Aopen%20string_processing -
hug_parens_with_braces_and_square_bracketsNote this is already implemented as a Ruff preview feature (see below). So marking this as "done" here, and deferring to the below list for whether to stabilize. See also format: different behavior with black forhug_parens_with_braces_and_square_bracketsand generators #11375 -
multiline_string_handlingAccording to 2025 issue: "non goal. Maybe a simplified version of it that only joins implicitly concatenated strings"
Ruff preview styles
Ruff specific preview styles that we may want to stabilize
-
hug_parens_with_braces_and_square_brackets -
no_chaperone_for_escaped_quote_in_triple_quoted_docstring -
blank_line_before_decorated_class_in_stub
Ruff improvements
Open Bugs
Existing bugs in the ruff formatter for which no preview style exists.
Require a new style guide
Bug fixes that change how existing code is formatted and require a breaking change.
- Unnecessary parantheses to long patterns with
ascaptures Avoid extra parentheses for longmatchpatterns withascaptures #21176 - Dict key split to multiline (deviation from black)
- Ruff splits subscript targets instead of parenthesizing the value
- Handling of blank lines between module docstring and a comment (unclear if it requires a new style guide) @konstin
- Parenthesize assignment values that fit into the line length
- Handle over-long lambda expressions (possibly requires a new style guide)
Bug fixes that don't change existing formatting
Bug fixes that don't require a new style guide because they don't change existing code
- Range formatting does not handle whitespace before new classes
- Formatter inserts trailing newline at the end of a file even when inside a fmt: off region
- Not respecting
fmt: skip(possibly related tofix_fmt_skip_in_one_linersBlack preview style) - Preserve trailing whitespace in docstring examples
- Incorrect docstring code block formatting for statement sequences
- Handling of empty lines after
; - Suppressing statement sequences
- Using
fmt:skipto suppress compound statements - Parenthesized expression with comment on right hand side in assignment produces invalid syntax
- Fuzzer: comment in middle of operand causes panic
- Fuzzer: debug assert on dangling comments failed
Reacted by sage, Avasam and pygarap
Reacted by Vladimir Korsakov
Metadata
Metadata
Assignees
Labels
formatterRelated to the Ruff formatterRelated to the Ruff formatterhelp wantedContributions especially welcomeContributions especially welcomestyleHow should Ruff-formatted code lookHow should Ruff-formatted code look
Activity
s-banach commentedon Sep 20, 2025
I have been using ruff format with
preview = truesince 2023, just for this one feature.The only reason I'm reading this issue is to see whether it will be stabilized.
MeGaGiGaGon commentedon Sep 20, 2025
ruffalready has the behavior fromnormalize_cr_newlines. I guess it was technically a formatting deviation before? But like usual no one noticed because dealing with newlines is so annoying.Demonstrating difference
Input code powershell escaped:
"a`rb`nc`r`n#1"Input code backslash escaped:
a\rb\nc\r\n#1\r\na\nb\nc\n# 1\na\rb\rc\r# 1\ra\rb\rc\r# 1\rInput code without visible newlines:
Input code with written out newlines:
Where the
#1at the end is to cause the reformatting.Where
Get-Escaped-Contentis a custom powershell function specifically to help deal with these annoying newlines:MichaReiser commentedon Sep 20, 2025
For reference the tracking issue for the 2025 style guide.
https://github.com/psf/black/pull/3440because of Nested expression formatting #12856.multiline_string_handling: Ruff now automatically joins implicitly concatenated strings. That's as far as we want to go for now.string_processingis@vlkorsakov is there a specific change that you dislike or do you dislike style changes in general?
MeGaGiGaGon commentedon Sep 20, 2025
Ruff already has part of
string_processingin that short string literals will be merged . Also part of it is splitting long string literals, see the docs for more info, butstring_processingis almost certainly going to remain unstable for 2026. See the 2024 Black Stable Style issue psf/black#4042 for more details, but there are still many outstanding serious issues https://github.com/psf/black/issues?q=is%3Aissue%20state%3Aopen%20string_processing . (But it also won't be removed since there are a ton of people that like it, so it's stuck in a difficult place)dylwil3 commentedon Sep 26, 2025
It looks like the preview style
wrap_comprehension_inalso results in quite a few added parentheses: https://github.com/psf/black/blob/903bef54aa72e111c034ccec9997aac82bafbacc/tests/data/cases/preview_wrap_comprehension_in.pySo we may get into a similar situation as with #12856
MichaReiser commentedon Nov 10, 2025
Black published a new release today and they moved multiline_string from unstable into preview. We should double check how their multiline string handling differs from our (I might have confused it with the string_processing unstable style)
ntBre commentedon Nov 10, 2025
I tried updating our Black tests again, and the only changes to the multiline string styles were from this PR: psf/black#4760, deleting some of the cases that I think do relate more to
string_processing. So ourpreview_multiline_stringssnapshot should still accurately reflect how closely we match Black.Mostly it looks like we insert more breaks around multiline strings:
ruff/crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_multiline_strings.py.snap
Lines 336 to 345 in deeda56
hauntsaninja commentedon Nov 10, 2025
Does ruff have anything planned for #12856 ? Especially curious about
parenthesize_conditional_expressions, I get asked about that at work sometimesMichaReiser commentedon Nov 11, 2025
I see. I suggest we wait then. Ruff uses some heuristics to preserve the indent for multiline strings to reduce the diff compared to the old style guide and I remember that it was a main concern for Black when they considered stabilizing in previous years. We can always follow along next year if the change works well for Black.
Unfortunately not. I very much hope that we'll have more dedicated time to improve Ruff's style guide next year. Shipping #12856 probably also requires formatter editions (that are independent of the ruff version), because I expect the diff compared to the current style guide to be rather large. You can upvote (or comment on) #12856 or #9722 specifically. This would help us prioritize the work next year.
laymonage commentedon Nov 11, 2025
I'd like to suggest #21380 to be included in the "Stabilized in Black and not available in Ruff (even in preview)" section, next to #21110 that has been released. Thanks!
dylwil3 commentedon Dec 6, 2025
Black added a new preview style on
main(not yet released): psf/black#4865Removes LHS parentheses in examples such as
At the moment we preserve the user's parentheses or lack thereof.
I'm sort of okay making this a preview style, but I would hesitate stabilizing for 2026 - it seems like not a huge improvement but would cause big diffs everywhere.
MichaReiser commentedon Dec 6, 2025
I'm not sure I follow the reasoning here. The diff size doesn't depend on when we stabilize it; it's only defined by the change itself.
Removing the parentheses around tuples requires matching on the target and call the tuple formatting with
TupleParentheses::NeverPreserve.Removing unnecessary parentheses around
(b)might be slightly trickier. I do agree that this isn't a change that we need to rush and I'd keep our existing prioritization:MichaReiser commentedon Dec 9, 2025
Regarding:
(c, *_) = a(). We intentionally preserve tuple parentheses in more places than black because it can be very easy to miss that something's a tuple if the parentheses are missing. I don't remember the exact details but we should ensure we preserve parentheses in assignment targets the same as we do in assignment values.hugovk commentedon Jan 18, 2026
Black 26.1.0 is now out with their new 2026 style:
https://github.com/psf/black/releases/tag/26.1.0
RazerM commentedon Jan 20, 2026
Now that black has stabilized multiline_string_handling I'd like to see it in ruff, it's the one thing keeping me from adopting ruff format in some projects.
To summarise:
ruff allows this:
but changes:
to
which I can't get behind
MichaReiser commentedon Jan 20, 2026
@RazerM please create a separate issue to discuss this style change.