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

Adding a comment on its own line in a list comprehension introduces line breaks in the code. #1337

Open
bersbersbers opened this issue Apr 8, 2020 · 0 comments
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: style What do we want Blackened code to look like?

Comments

@bersbersbers
Copy link

Describe the bug
A clear and concise description of what the bug is the title:

Adding a comment on its own line in a list comprehension introduces line breaks in the code.

To Reproduce

  1. Take the code below
  2. Run Black on it
  3. Notice that in the second block, ** 2 for i in some_long_var_name is - unnecessarily - broken in two lines.

Expected behavior
i ** 2 for i in some_long_var_name should not be broken in two lines.

Environment

  • Version: 19.10b0
  • OS and Python version: Windows 10, 3.8.2

Does this bug also happen on master?

Yes.

"""Bug."""
if True and True:
    if True and True:
        if True and True:
            if True and True:
                print(
                    list(
                        map(
                            lambda some_long_var_name: [
                                i ** 2 for i in some_long_var_name
                            ],
                            [[1, 2, 3], [4, 5, 6]],
                        )
                    )
                )

                print(
                    list(
                        map(
                            lambda some_long_var_name: [
                                # Why does this comment force the next line into two?
                                i ** 2 for i in some_long_var_name
                            ],
                            [[1, 2, 3], [4, 5, 6]],
                        )
                    )
                )
@bersbersbers bersbersbers added the T: bug Something isn't working label Apr 8, 2020
@JelleZijlstra JelleZijlstra added F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: style What do we want Blackened code to look like? and removed T: bug Something isn't working labels May 30, 2021
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. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants