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

Single line with binary operator in commented list causes additional line breaks #4026

Open
zyzzyxdonta opened this issue Nov 6, 2023 · 1 comment
Labels
F: linebreak How should we split up lines? T: bug Something isn't working

Comments

@zyzzyxdonta
Copy link

zyzzyxdonta commented Nov 6, 2023

Describe the bug

Inside a list, a comment followed by a single line with division operator causes additional lines breaks before each division operator.

To Reproduce

For example, take this code:

import pathlib

foobar = [
    # comment
    pathlib.Path("foo") / "bar" / "baz",
]

fizzbuzz = [
    # comment
    23 / 7
]

And run black on it with the default config.

The resulting formatted code is:

import pathlib

foobar = [
    # comment
    pathlib.Path("foo")
    / "bar"
    / "baz",
]

fizzbuzz = [
    # comment
    23
    / 7
]

Expected behavior

The formatting doesn't change (apart from maybe the trailing comma).

Environment

  • Black's version: 23.10.1 (compiled: yes)
  • OS and Python version: Fedora Linux 38 / Python 3.11.6

Additional context

Formatting does not occur if the expression is enclosed in parentheses, e.g.

(pathlib.Path("foo") / "bar" / "baz")

It also doesn't happen any more once additional lines are introduced to the lists.

@zyzzyxdonta zyzzyxdonta added the T: bug Something isn't working label Nov 6, 2023
@zyzzyxdonta zyzzyxdonta changed the title Single line with division operator in commented list causes additional line breaks Single line with binary operator in commented list causes additional line breaks Nov 6, 2023
@zyzzyxdonta
Copy link
Author

This also occurs with other operators like +, -, *.

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? T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants