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

Consider not breaking line on outermost parenthesis #500

Closed
cdeil opened this issue Sep 6, 2018 · 3 comments
Closed

Consider not breaking line on outermost parenthesis #500

cdeil opened this issue Sep 6, 2018 · 3 comments
Labels
R: duplicate This issue or pull request already exists

Comments

@cdeil
Copy link

cdeil commented Sep 6, 2018

First of all - thank you for making black!
I'm applying it to my main project (Gammapy) today.

There are a few examples where I think that black gives non-ideal results, and wanted to mention them here. If those have been discussed before, I apologise, please just close this issue.

I think this is nice:

things = OrderedDict([
    ('ham', 'spam'),
    ('bla bla bla bla', 'some more text here'),
])

and putting [ and ] on a separate line like black does is not an improvement:

things = OrderedDict(
    [
        ("ham", "spam"),
        ("bla bla bla bla", "some more text here"),
    ]
)

I read through the black description, and see that this is intended behaviour to always add line breaks on the outermost parenthesis. Is it possible / up for debate to change this in some cases?

This is another case:

text  = """
Hello hallo
allo allo
"""[1:-1]

where black gives this output:

text = """
Hello hallo
allo allo
"""[
    1:-1
]

and I think the input formatting is better readable than the black output.

@zsol
Copy link
Collaborator

zsol commented Sep 7, 2018

I agree that the formatting in your second example is terrible. That's because black treats those multiline strings as if they never fit a line. #256 tracks that.

I'm not so sure about your first example. I like that black makes it very explicit that we're passing a list instead of two parameters. On the other hand I see where you're coming from as the result is a bit more verbose.

@zsol zsol added the T: style What do we want Blackened code to look like? label Sep 7, 2018
@lithammer
Copy link

What I don't like about the first example is that Black robs you of 4 precious spaces (yes I use 79 instead of 88). On the other hand, I agree that it's more explicit (a good thing).

@ambv
Copy link
Collaborator

ambv commented Sep 26, 2018

Thanks for your report! I will close this as a duplicate of #256. We'll track the fix there.

We won't be changing formatting of consecutive bracket pairs.

@ambv ambv closed this as completed Sep 26, 2018
@ambv ambv added R: duplicate This issue or pull request already exists and removed T: style What do we want Blackened code to look like? labels Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants