Skip to content

Comments

Update Black tests#22405

Merged
dylwil3 merged 2 commits intoastral-sh:mainfrom
dylwil3:update-black-fixtures
Jan 6, 2026
Merged

Update Black tests#22405
dylwil3 merged 2 commits intoastral-sh:mainfrom
dylwil3:update-black-fixtures

Conversation

@dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Jan 5, 2026

I am updating these because we didn't have test coverage for the different handling of fmt: skip comments applied to multiple statements on the same line. This is in preparation for #22119 (to show before/after deviations).

Follows the same procedure as in #20794

Edit: As it happens, the new fixtures do not even cover the case relevant to #22119 - they just deal with the already handled case of a one-line compound statement. Nevertheless, it seems worthwhile to make this update, especially since it uncovered a bug.

@dylwil3 dylwil3 added internal An internal refactor or improvement formatter Related to the formatter testing Related to testing Ruff itself and removed internal An internal refactor or improvement labels Jan 5, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 5, 2026

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Comment on lines +72 to +75


def f(x: int): return x # fmt: skip

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These empty lines look like a bug to me, presumably in the implementation of fmt skip for clauses. I will open an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened: #22406

Comment on lines -244 to -245
- # ...but comments still get reformatted even though they should not be
+ # ...but comments still get reformatted even though they should not be
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Ruff is getting it right here

Comment on lines +96 to +110
## Black Differences

```diff
--- Black
+++ Ruff
@@ -46,8 +46,7 @@
[
(1, 2),
# # fmt: off
- (3,
- 4),
+ (3, 4),
# # fmt: on
(5, 6),
]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known deviation - we don't support off/on within an expression.

Comment on lines +23 to +24
-with open("file.txt") as f: content = f.read() # fmt: skip
+with open("file.txt") as f: content = f.read() # fmt: skip
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known deviation: we format the skip comments

Comment on lines +43 to +51
t = (
- {"foo": "very long string", "bar": "another very long string", "baz": "we should run out of space by now"}, # fmt: skip
+ {
+ "foo": "very long string",
+ "bar": "another very long string",
+ "baz": "we should run out of space by now",
+ }, # fmt: skip
{"foo": "bar"},
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known deviation: suppressing inside an expression

Comment on lines +53 to +63
- "editor:swap-line-down": [{"key": "ArrowDown", "modifiers": ["Alt", "Mod"]}], # fmt: skip
- "editor:swap-line-up": [{"key": "ArrowUp", "modifiers": ["Alt", "Mod"]}], # fmt: skip
- "editor:toggle-source": [{"key": "S", "modifiers": ["Alt", "Mod"]}], # fmt: skip
+ "editor:swap-line-down": [
+ {"key": "ArrowDown", "modifiers": ["Alt", "Mod"]}
+ ], # fmt: skip
+ "editor:swap-line-up": [
+ {"key": "ArrowUp", "modifiers": ["Alt", "Mod"]}
+ ], # fmt: skip
+ "editor:toggle-source": [{"key": "S", "modifiers": ["Alt", "Mod"]}], # fmt: skip
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known deviation: suppression within expression

Comment on lines +49 to +53
## Black Differences

```diff
--- Black
+++ Ruff
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are all equivalent to the known deviations in f-string formatting.

Comment on lines +34 to +41
import ast
import collections # fmt: skip
import dataclasses
+
# fmt: off
import os
# fmt: on
```
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is expected because this option for import sorting is covered by the linter and not the formatter (at the moment)

Comment on lines +19 to +38
## Black Differences

```diff
--- Black
+++ Ruff
@@ -1,9 +1,9 @@
def foo(
- a, # type: int
+ a, # type:int
b, # type: str
c, # type: List[int]
- d, # type: Dict[int, str]
- e, # type: ignore
+ d, # type: Dict[int, str]
+ e, # type: ignore
f, # type : ignore
g, # type : ignore
):
```

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected since we have not implemented this preview style

Comment on lines +25 to +44
## Black Differences

```diff
--- Black
+++ Ruff
@@ -6,10 +6,10 @@


# Single variable with unnecessary parentheses
-b = a()[0]
+(b) = a()[0]

# Tuple unpacking with unnecessary parentheses
-c, *_ = a()
+(c, *_) = a()

# These should not be changed - parentheses are necessary
(d,) = a() # single-element tuple
```

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Known deviation

@dylwil3 dylwil3 marked this pull request as ready for review January 5, 2026 18:42
@dylwil3 dylwil3 requested a review from MichaReiser as a code owner January 5, 2026 18:42
@dylwil3 dylwil3 merged commit 924b297 into astral-sh:main Jan 6, 2026
43 checks passed
@dylwil3 dylwil3 deleted the update-black-fixtures branch January 6, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the formatter testing Related to testing Ruff itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants