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:
Charlie Marsh 2023-08-03 21:28:05 -04:00 committed by GitHub
parent d3aa8b4ee0
commit 1d8759d5df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 265 additions and 99 deletions

View file

@ -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
}

View file

@ -25,3 +25,9 @@ len(
# trailing
)
)
len(
# leading
a for b in c
# trailing
)

View file

@ -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
]