mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Fix handling of trailing target comment (#9051)
This commit is contained in:
parent
a224f19903
commit
d0d88d9375
3 changed files with 25 additions and 1 deletions
|
@ -67,3 +67,12 @@ def main() -> None:
|
||||||
db_request.POST["name"]
|
db_request.POST["name"]
|
||||||
)
|
)
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
c = b[dddddd, aaaaaa] = (
|
||||||
|
a[
|
||||||
|
aaaaaaa,
|
||||||
|
bbbbbbbbbbbbbbbbbbb
|
||||||
|
]
|
||||||
|
# comment
|
||||||
|
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Format<PyFormatContext<'_>> for FormatTargets<'_> {
|
||||||
if let Some((first, rest)) = self.targets.split_first() {
|
if let Some((first, rest)) = self.targets.split_first() {
|
||||||
let comments = f.context().comments();
|
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
|
ParenthesizeTarget::Always
|
||||||
} else if has_own_parentheses(first, f.context()).is_some() {
|
} else if has_own_parentheses(first, f.context()).is_some() {
|
||||||
ParenthesizeTarget::Never
|
ParenthesizeTarget::Never
|
||||||
|
|
|
@ -73,6 +73,15 @@ def main() -> None:
|
||||||
db_request.POST["name"]
|
db_request.POST["name"]
|
||||||
)
|
)
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
c = b[dddddd, aaaaaa] = (
|
||||||
|
a[
|
||||||
|
aaaaaaa,
|
||||||
|
bbbbbbbbbbbbbbbbbbb
|
||||||
|
]
|
||||||
|
# comment
|
||||||
|
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
```
|
```
|
||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
@ -151,6 +160,12 @@ def main() -> None:
|
||||||
db_request.POST["name"]
|
db_request.POST["name"]
|
||||||
)
|
)
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
c = b[dddddd, aaaaaa] = (
|
||||||
|
a[aaaaaaa, bbbbbbbbbbbbbbbbbbb]
|
||||||
|
# comment
|
||||||
|
) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue