It also does not collapse lines when there’s a trailing comma.
Your output seems to be from black. IMO it’s insane to collapse lines when there are line comments.
$ uvx ruff format --diff formatting.py
--- formatting.py
+++ formatting.py
@@ -1,8 +1,4 @@
-no_comma = {
- "x": 3,
- "y": 42,
- "z": 2
-}
+no_comma = {"x": 3, "y": 42, "z": 2}
with_comma = {
"x": 3,
@@ -12,6 +8,6 @@
comment = {
"x": 3,
- "y": 42, # Answer to the Ultimate Question!
- "z": 2
+ "y": 42, # Answer to the Ultimate Question!
+ "z": 2,
}
1 file would be reformatted
(I intentionally switched to double quotes since that really is a stylistic choice in Python, you can escape in both, and if you use double quotes inside of single quotes ruff leaves it as-is)