mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Generalize comment-after-bracket handling to lists, sets, etc. (#6320)
## Summary We already support preserving the end-of-line comment in calls and type parameters, as in: ```python foo( # comment bar, ) ``` This PR adds the same behavior for lists, sets, comprehensions, etc., such that we preserve: ```python [ # comment 1, 2, 3, ] ``` And related cases.
This commit is contained in:
parent
d3aa8b4ee0
commit
1d8759d5df
20 changed files with 265 additions and 99 deletions
|
@ -86,3 +86,10 @@ selected_choices = {
|
|||
k: str(v)
|
||||
for vvvvvvvvvvvvvvvvvvvvvvv in value if str(v) not in self.choices.field.empty_values
|
||||
}
|
||||
|
||||
{
|
||||
k: v
|
||||
for ( # foo
|
||||
|
||||
x, aaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaayaaaay) in z
|
||||
}
|
||||
|
|
|
@ -25,3 +25,9 @@ len(
|
|||
# trailing
|
||||
)
|
||||
)
|
||||
|
||||
len(
|
||||
# leading
|
||||
a for b in c
|
||||
# trailing
|
||||
)
|
||||
|
|
|
@ -32,3 +32,15 @@ c1 = [ # trailing open bracket
|
|||
2, # trailing item
|
||||
# leading close bracket
|
||||
] # trailing close bracket
|
||||
|
||||
|
||||
[ # end-of-line comment
|
||||
]
|
||||
|
||||
[ # end-of-line comment
|
||||
# own-line comment
|
||||
]
|
||||
|
||||
[ # end-of-line comment
|
||||
1
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue