-
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
Is it possible to relax the rule that put the code in one line if it can? #1054
Comments
What if Black would let you control how multiline expressions are exploded by checking for a trailing comma? #826 is working towards that direction, but the implementation unfortunately won't work for your use case (since these are neither collection literals nor top level expressions. |
Yes, I think that could work and as it's likely to get merged soon.
I'll give a try to the branch, the example I posted are probably a little incomplete, they are nested inside a class so I believe this should be fine if we add a trailing comma. That would require some manual modifications to the code in some case but if I if works and all the team member start using it and use that convention, that would certainly remove a lot of manual work in our case. |
I tried it but it doesn't work. It doesn't seem to reformat method call but only syntax for tuple, dict, list. |
I would really like to see this addition as well. I actually thought that #826 was going to allow this, but apparently it still forces everything to one line. All I would like to see is that black allows me to choose between the two options. If a line is too long, black should still provide a default. But if I have decided I want to break a call into multiple lines, there is no reason for black to force some lines into the other style.
This is much easier to read and diff. (Desired format). def something(
argument1: Optional[str] = "foo",
argument2: Optional[Union[str, int]] = "bar",
):
pass
something(
argument1="asdf",
argument2="qwer",
) This is harder to read and diff. (Current format). def something(
argument1: Optional[str] = "foo", argument2: Optional[Union[str, int]] = "bar",
):
pass
something(
argument1="asdf", argument2="qwer",
) |
@thnee exactly. I did a fork that technically implement the leading command on function call but it doesn't seem to be very stable. I didn't look further into it yet. https://github.com/llacroix/black/commit/ddc68aa1829c3bcabcad492975ae7ad70d5d7201 When calling black on black with this commit, it fails as it seems to give different results between passes. So if someone can fix my mistakes and make it work, I'd be happy. Or give some pointers on why it's not working. |
I, too, would love to be able to tell Black not to force everything to one line. |
I think this is fixed by pull request #1612. |
Agreed. |
Howdy! Sorry you're having trouble. To expedite your experience,
provide some basics for me:
Operating system: Linux
Python version: 3.7
Black version:19.3b0
Here's a snippet of code:
That becomes:
Ideally, I would prefer if black didn't try to reduce the amount of lines and kept parameters on the same indent. The reason to do so is that the parameters on each line are at the same indent and it's easy to get from one to the other in vim without having to move the cursor only vertically. It also reduce eye movement so if you have a screen with high vertical resolution, it's easier to read code than moving eyes from left to right to read line of code.
In some case, I'd rather have it increase the amount of lines instead of packing the most it can on one line.
One idea thought is to reduce the amount of token on one line. So if we parse
as
And the configuration is max 10 token on one line:
It would result with something like this:
which would later get reformatted to:
Still not exactly what I'd like but having a setting that favor multiline over one line would be nice.
The text was updated successfully, but these errors were encountered: