-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Respect comments on different lines #1353
Comments
Just another example of where this happens, with function arguments: def generate_unsplit_data(
rf,
T=5e5, # μs
nt=5001,
z_max=50, # μm
mass=86, # Dalton
):
pass gets reformatted as def generate_unsplit_data(
rf, T=5e5, nt=5001, z_max=50, mass=86, # μs # μm # Dalton
):
pass I would expect Black to leave the original code unchanged. |
@goerz that code is left unchanged on the latest release (due to the magic trailing comma). |
Can confirm. I was still running To be fair, though, the new trailing-coma-behavior probably makes this a much less pressing issue. As far as I can tell, it also applies to the OP, and I can't really think of an example where one couldn't add a trailing comma to get around Black's behavior 🤷 |
This is still an issue when using constructs without magic comma. For example, I like to do the following: __all__ = (
[ # Classes
"Class1",
"Class2",
"Class3",
] + [ # Functions
"function1",
"function2",
"function3",
]
) which black (version 21.9b0) will reformat to __all__ = ["Class1", "Class2", "Class3",] + [ # Classes # Functions
"function1",
"function2",
"function3",
] UGLY! |
Couldn't you just do: __all__ = [
# Classes
"Class1",
"Class2",
"Class3",
# Functions
"function1",
"function2",
"function3",
] |
@NakulK48 Yes, I realize my example was not that good and it should probably be rewritten in the way you presented. There might be other examples that are more applicable where some terms are literal and others are dynamic. Nevertheless I still think even if the way I originally wrote it is sub-optimal it is still way better than what black converted it to. |
This is more cases of #379. |
Describe the style change A clear and concise description of how the style can be
improved.
If a line has a comment at the end of it, it shouldn't be combined with adjacent lines
Examples in the current Black style Think of some short code snippets that show
how the current Black style is not great:
(n.b. run with
--line-length 120
)As you can see, it's much less obvious which comment refers to which entry.
Desired style How do you think Black should format the above snippets:
(unchanged from how I wrote it)
Additional context Add any other context about the problem here.
This came up when I was trying to parametrize a test and leave some comments explaining each of the cases.
The text was updated successfully, but these errors were encountered: