mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-14 20:40:28 +00:00
Fix StmtAnnAssign
formatting by mirroring StmtAssign
(#5732)
## 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.
This commit is contained in:
parent
b1781abffb
commit
549173b395
5 changed files with 69 additions and 15 deletions
|
@ -4,21 +4,28 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/
|
|||
---
|
||||
## Input
|
||||
```py
|
||||
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
|
||||
```
|
||||
|
||||
## 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)
|
||||
# Regression test: Don't forget the parentheses in the value when breaking
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: int = (
|
||||
a + 1 * a
|
||||
)
|
||||
|
||||
|
||||
# Regression test: Don't forget the parentheses in the annotation when breaking
|
||||
class DefaultRunner:
|
||||
task_runner_cls: (
|
||||
TaskRunnerProtocol | typing.Callable[[], typing.Any]
|
||||
) = DefaultTaskRunner
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue