Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing comma gives newline on wrong expressions #3268

Open
jlubcke opened this issue Sep 12, 2022 · 3 comments
Open

Trailing comma gives newline on wrong expressions #3268

jlubcke opened this issue Sep 12, 2022 · 3 comments
Labels
F: linebreak How should we split up lines? F: trailing comma Full of magic T: bug Something isn't working

Comments

@jlubcke
Copy link

jlubcke commented Sep 12, 2022

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
@jlubcke jlubcke added the T: bug Something isn't working label Sep 12, 2022
@felix-hilden felix-hilden added F: trailing comma Full of magic F: linebreak How should we split up lines? labels Sep 14, 2022
@KindaOK
Copy link

KindaOK commented Nov 9, 2022

I'll take a look at the issue. It also comes up for me in Python 3.8 (Windows) on Black 22.10.0

@KindaOK
Copy link

KindaOK commented Nov 16, 2022

Draft Pull request at #3377

@RedGuy12
Copy link
Contributor

RedGuy12 commented May 9, 2024

Is this related to #4254?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? F: trailing comma Full of magic T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants