Conversation
|
|
|
||
|
|
||
| def f(x: int): return x # fmt: skip | ||
|
|
There was a problem hiding this comment.
These empty lines look like a bug to me, presumably in the implementation of fmt skip for clauses. I will open an issue.
| - # ...but comments still get reformatted even though they should not be | ||
| + # ...but comments still get reformatted even though they should not be |
There was a problem hiding this comment.
I think Ruff is getting it right here
| ## Black Differences | ||
|
|
||
| ```diff | ||
| --- Black | ||
| +++ Ruff | ||
| @@ -46,8 +46,7 @@ | ||
| [ | ||
| (1, 2), | ||
| # # fmt: off | ||
| - (3, | ||
| - 4), | ||
| + (3, 4), | ||
| # # fmt: on | ||
| (5, 6), | ||
| ] |
There was a problem hiding this comment.
Known deviation - we don't support off/on within an expression.
| -with open("file.txt") as f: content = f.read() # fmt: skip | ||
| +with open("file.txt") as f: content = f.read() # fmt: skip |
There was a problem hiding this comment.
Known deviation: we format the skip comments
| 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"}, | ||
| ) |
There was a problem hiding this comment.
Known deviation: suppressing inside an expression
| - "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 | ||
| } |
There was a problem hiding this comment.
Known deviation: suppression within expression
| ## Black Differences | ||
|
|
||
| ```diff | ||
| --- Black | ||
| +++ Ruff |
There was a problem hiding this comment.
I believe these are all equivalent to the known deviations in f-string formatting.
| import ast | ||
| import collections # fmt: skip | ||
| import dataclasses | ||
| + | ||
| # fmt: off | ||
| import os | ||
| # fmt: on | ||
| ``` |
There was a problem hiding this comment.
This is expected because this option for import sorting is covered by the linter and not the formatter (at the moment)
| ## 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 | ||
| ): | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Expected since we have not implemented this preview style
| ## 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 | ||
| ``` | ||
|
|
I am updating these because we didn't have test coverage for the different handling of
fmt: skipcomments 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.