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

inline comments make subscription look really bad #1125

Open
wimglenn opened this issue Oct 30, 2019 · 4 comments
Open

inline comments make subscription look really bad #1125

wimglenn opened this issue Oct 30, 2019 · 4 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

@wimglenn
Copy link

wimglenn commented Oct 30, 2019

input:

my_value = my_list[0]  # developer wanted to explain something here with an inline comment

actual output (v19.10b0):

my_value = my_list[
    0
]  # developer wanted to explain something here with an inline comment

desired output:

# developer wanted to explain something here with an inline comment
my_value = my_list[0]

Instead of wrapping long lines so weird, do you think it would be feasible to just move these comment above instead?

@wimglenn wimglenn added the T: style What do we want Blackened code to look like? label Oct 30, 2019
@zsol
Copy link
Collaborator

zsol commented Oct 31, 2019

It's hard to do in the general sense because the comment might have some meaning attached to that line (think code analysis tools like flake8 or mypy), and so moving the comment might change that meaning.

@ocehugo
Copy link

ocehugo commented Apr 24, 2020

Related to #1187

I don't know the internals, but if other code analysis tools got simple functions to return all possible pragmas, a feasible solution is to add those to a "dont split inline comment" rule.

@sebastian-fredriksson-bernholtz

@zsol The existing behaviour creates the same issue in many cases - if not most/all.

I really think black should leave inline comments be. As I described in #1187 (comment) inline comments are probably inline for a reason. Code analysis tool is a very strong argument.

@ichard26 ichard26 added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label Apr 2, 2021
@th0ger
Copy link

th0ger commented Aug 27, 2021

Ok, inline comments should stay inline. But are inline comments handled consistently?

# in:

a = 1/3  # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
b = (
    0.333333333333333333333333333333333333333333333333333333333333
) # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor

# out:

a = (
    1 / 3
)  # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
b = 0.333333333333333333333333333333333333333333333333333333333333  # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor

Here, Black is clearly doing a terrible job in reducing the max line length. The introduction of parenthesis for a could have been applied to (or kept for) b as well, reducing line length significantly.

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

6 participants