Skip to content

Commit

Permalink
Fix handling of trailing target comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Dec 8, 2023
1 parent a224f19 commit abf64db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ def main() -> None:
db_request.POST["name"]
)
)[0]


c = b[dddddd, aaaaaa] = (
a[
aaaaaaa,
bbbbbbbbbbbbbbbbbbb
]
# comment
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2 changes: 1 addition & 1 deletion crates/ruff_python_formatter/src/statement/stmt_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Format<PyFormatContext<'_>> for FormatTargets<'_> {
if let Some((first, rest)) = self.targets.split_first() {
let comments = f.context().comments();

let parenthesize = if comments.has_leading(first) {
let parenthesize = if comments.has_leading(first) || comments.has_trailing(first) {
ParenthesizeTarget::Always
} else if has_own_parentheses(first, f.context()).is_some() {
ParenthesizeTarget::Never
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def main() -> None:
db_request.POST["name"]
)
)[0]
c = b[dddddd, aaaaaa] = (
a[
aaaaaaa,
bbbbbbbbbbbbbbbbbbb
]
# comment
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

## Output
Expand Down Expand Up @@ -151,6 +160,12 @@ def main() -> None:
db_request.POST["name"]
)
)[0]
c = b[dddddd, aaaaaa] = (
a[aaaaaaa, bbbbbbbbbbbbbbbbbbb]
# comment
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```


Expand Down

0 comments on commit abf64db

Please sign in to comment.