Skip to content

Commit abf64db

Browse files
committed
Fix handling of trailing target comment
1 parent a224f19 commit abf64db

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assign.py

+9
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ def main() -> None:
6767
db_request.POST["name"]
6868
)
6969
)[0]
70+
71+
72+
c = b[dddddd, aaaaaa] = (
73+
a[
74+
aaaaaaa,
75+
bbbbbbbbbbbbbbbbbbb
76+
]
77+
# comment
78+
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

crates/ruff_python_formatter/src/statement/stmt_assign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Format<PyFormatContext<'_>> for FormatTargets<'_> {
6969
if let Some((first, rest)) = self.targets.split_first() {
7070
let comments = f.context().comments();
7171

72-
let parenthesize = if comments.has_leading(first) {
72+
let parenthesize = if comments.has_leading(first) || comments.has_trailing(first) {
7373
ParenthesizeTarget::Always
7474
} else if has_own_parentheses(first, f.context()).is_some() {
7575
ParenthesizeTarget::Never

crates/ruff_python_formatter/tests/snapshots/format@statement__assign.py.snap

+15
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def main() -> None:
7373
db_request.POST["name"]
7474
)
7575
)[0]
76+
77+
78+
c = b[dddddd, aaaaaa] = (
79+
a[
80+
aaaaaaa,
81+
bbbbbbbbbbbbbbbbbbb
82+
]
83+
# comment
84+
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
7685
```
7786

7887
## Output
@@ -151,6 +160,12 @@ def main() -> None:
151160
db_request.POST["name"]
152161
)
153162
)[0]
163+
164+
165+
c = b[dddddd, aaaaaa] = (
166+
a[aaaaaaa, bbbbbbbbbbbbbbbbbbb]
167+
# comment
168+
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
154169
```
155170

156171

0 commit comments

Comments
 (0)