black
black copied to clipboard
Trailing comma gives newline on wrong expressions
Describe the bug
Black in some cases put the wrong parts on separate lines when having a trailing comma.
For example this:
assert foo(1, 2, 3,)[
0
] == {'bar': 'baz'}
Expected result was something like:
assert foo(
1,
2,
3,
)[0] == {'bar': 'baz'}
To Reproduce
Minimal example:
a = [1,][2]()
b = [1,][2](3)
Expected:
a = [
1,
][2]()
b = [
1,
][2](3)
Actual result:
a = [
1,
][2]()
b = [1,][
2
](3)
Environment
- Black's version: 22.8.0 (and main)
- OS and Python version: Mac
I'll take a look at the issue. It also comes up for me in Python 3.8 (Windows) on Black 22.10.0
Draft Pull request at #3377
Is this related to #4254?