-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary `StmtAnnAssign` would not insert parentheses when breaking the same way `StmtAssign` does, causing unstable formatting and likely some syntax errors. ## Test Plan I added a regression test.
- Loading branch information
Showing
5 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/ann_assign.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
tree_depth += 1 | ||
# Regression test: Don't forget the parentheses in the value when breaking | ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: int = a + 1 * a | ||
|
||
greeting += "This is very long, formal greeting for whomever is name here. Dear %s, it will break the line" % len( | ||
name | ||
) | ||
|
||
# Regression test: Don't forget the parentheses in the annotation when breaking | ||
class DefaultRunner: | ||
task_runner_cls: TaskRunnerProtocol | typing.Callable[[], typing.Any] = DefaultTaskRunner |
5 changes: 5 additions & 0 deletions
5
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/aug_assign.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tree_depth += 1 | ||
|
||
greeting += "This is very long, formal greeting for whomever is name here. Dear %s, it will break the line" % len( | ||
name | ||
) |
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
crates/ruff_python_formatter/tests/snapshots/format@statement__aug_assign.py.snap
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
source: crates/ruff_python_formatter/tests/fixtures.rs | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/aug_assign.py | ||
--- | ||
## Input | ||
```py | ||
tree_depth += 1 | ||
greeting += "This is very long, formal greeting for whomever is name here. Dear %s, it will break the line" % len( | ||
name | ||
) | ||
``` | ||
|
||
## Output | ||
```py | ||
tree_depth += 1 | ||
greeting += ( | ||
"This is very long, formal greeting for whomever is name here. Dear %s, it will break the line" | ||
% len(name) | ||
) | ||
``` | ||
|
||
|
||
|