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

Comments end up colliding after reformatting multiline arithmetic expression #1033

Closed
cfbolz opened this issue Sep 24, 2019 · 3 comments
Closed
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs.

Comments

@cfbolz
Copy link

cfbolz commented Sep 24, 2019

Operating system: Ubuntu
Python version: Python 3.7.3
Black version: 19.3b0
Does also happen on master: Yes

Thanks a lot for all your amazing work on black!

I understand that always getting the placement of comments always right is probably hard or impossible, but I was still very surprised by this behaviour of black. This code:

x = (
    100 * 2 +  # direct ints
    400 * 4 +  # larger ints
    500 * 2 +  # unmodified
    1000 * 10  # floats
)

get's turned into:

x = (
    100 * 2
    + 400 * 4  # direct ints
    + 500 * 2  # larger ints
    + 1000 * 10  # unmodified  # floats
)

This means that the comments get moved to the wrong part of the expressions, and then in the last line two comments are merged. I'd hope for this kind of output:

x = (
    100 * 2  # direct ints
    + 400 * 4  # larger ints
    + 500 * 2  # unmodified
    + 1000 * 10  # floats
)
@hugovk
Copy link
Contributor

hugovk commented Sep 24, 2019

Duplicate of #771?

@cfbolz
Copy link
Author

cfbolz commented Sep 24, 2019

yes, I agree that it's very similar, but I found the fact that the two comments end up being next to each other particularly disconcerting.

@JelleZijlstra JelleZijlstra added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label May 30, 2021
@JelleZijlstra
Copy link
Collaborator

This is #379.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs.
Projects
None yet
Development

No branches or pull requests

3 participants