-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
How can I get the horizontal style #1345
Comments
which version of Black are you using? |
Remove that last comma: # in:
j = [1,
2,
3,
]
k = [1,
2,
3
]
# out:
j = [
1,
2,
3,
]
k = [1, 2, 3] $ black --version
black, version 19.10b0 |
@hugovk I just found that # in
data = [
-0.319,
-1.949,
-1.511,
1.176,
0.695,
-0.286,
0.392,
-0.094,
-0.714,
1.223,
1.811,
-2.57,
-0.014,
0.328,
-0.084,
-0.13,
-0.751,
0.47,
1.558,
0.714,
-0.999,
0.336]
# out
data = [
-0.319,
-1.949,
-1.511,
1.176,
0.695,
-0.286,
0.392,
-0.094,
-0.714,
1.223,
1.811,
-2.57,
-0.014,
0.328,
-0.084,
-0.13,
-0.751,
0.47,
1.558,
0.714,
-0.999,
0.336,
] |
Btw, I think it would be good if |
$ black --version
black, version 19.10b0 |
This is due to black's "magic trailing comma" handling, see #826 The intention here is to allow users to make changes while minimising diff size. |
@hauntsaninja True it is. But the fact is data = [ -0.319, -1.949, -1.511, 1.176, 0.695, -0.286, 0.392, -0.094, -0.714, 1.223, 1.811, -2.57, -0.014, 0.328, -0.084, -0.13,\
-0.751, 0.47, 1.558, 0.714, -0.999, 0.336, -2.51, -0.532, 2.495, -0.085, 0.165, 0.764, 0.865, -0.604, -1.083, 2.501, -1.074,\
-0.853, -0.241, -0.346, 0.472, -0.017, 1.013, 0.887, 2.154, -1.354, 0.966, -1.118, -1.374, -0.928, -0.664, 2.803, -0.133, 1.814,\
0.844, -0.719, 1.239, 0.49, 0.333, 0.518, 0.079, -1.33, -0.048, 1.335, -2.108, -1.772, -0.68, 0.151, -0.479, 0.749, 0.589, -1.048,\
-0.491, 1.125, 1.064, 0.4, 0.349, 0.193, -0.645, 0.038, 0.536, -0.675, 0.732, -1.442, -0.889, -0.976, 0.889, 1.296, 1.231, 0.934, -1.359,\
1.602, 0.186, -0.622, -0.08, -0.887, 0.109, 0.418, 0.945, -0.081, -0.32, -1.309, -0.497,0.346] And the output will be like this: data = [
-0.319,
-1.949,
...
...
...
-0.497,
0.346,
] I think |
@LovelyBuggies I believe the general recommendation in these cases is to use the |
@lorencarvalho Thanks for your help! Yep, I knew I could deal with this problem by manually reformatting. But I think it would be good for |
This is the one big problem I encounter in many projects. You have a function with some args: function(arg1, arg2, arg3) Now you add more args ... function(arg1, arg2, arg3, arg4, arg5, arg6, arg7) and at some point black reformats it to multiple lines and adds the trailing comma:
So far, so good! Now you remove some of the args again:
but black does not remove the trailing comma (it added earlier):
I think in these cases, black really should remove the trailing comma and put everything back in one line. Otherwise, one always has to manually remove it to see if black thinks it fits in one line or not. This is what we should get:
|
@jonasrauber Thanks. There are still some places I need to clarify.
In this case, I think black will add a comma first, and then format it to the verticle style. function(
- arg1, arg2, arg3, arg4,
+ arg1,
+ arg2,
+ arg3,
+ arg4,
)
The fact is I cannot even manually remove the comma to get |
If you write
it'll reformat to
if possible. So if you think it might fit on one line, then remove the last comma and see what happens. Remember that it won't remove the trailing comma automatically, since it has a special meaning to force one argument per line, which minimizes diffs. |
I don't think there's anything actionable in this issue. |
#1824 proposes a flag that will help with some of the things discussed in this issue |
I want to make my code reformatted like the code in the sample:
But I got:
What should I do for the black configure?
The text was updated successfully, but these errors were encountered: