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

Prefere linebreaks on binary operators over linebreaks at function parentheses #1254

Open
MarkusPiotrowski opened this issue Jan 31, 2020 · 2 comments
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@MarkusPiotrowski
Copy link

This is similar to other issues like #571, #587, #1050 and #1094.

Black should prefer line-breaking at binary operators over function parentheses or index/slice parentheses of one of the expression's elements. Especially in multi-element expression (e.g. calculations), the code becomes hard to read.

I have even seen worse examples than the two below, where a calculation becomes impossible to follow. But I think these two examples are quite clear.

Examples in the current Black style

# Example 1
            nogap_score = score_matrix[row - 1][col - 1] + match_fn(
               sequenceA[row - 1], sequenceB[col - 1]
            )

# Example 2
            ali_seqB = (row_distance - col_distance) * gap_char + sequenceB[
                lenB - 1 : col - 1 : -1
            ]

Desired style How do you think Black should format the above snippets:

# Example 1
            nogap_score = (
                score_matrix[row - 1][col - 1]
                + match_fn(sequenceA[row - 1], sequenceB[col - 1]
            )

# Example 2
            ali_seqB = (
                (row_distance - col_distance) * gap_char
                + sequenceB[lenB - 1 : col - 1 : -1 ]
             )
@MarkusPiotrowski MarkusPiotrowski added the T: style What do we want Blackened code to look like? label Jan 31, 2020
@ambv
Copy link
Collaborator

ambv commented Mar 4, 2020

Both of your examples increase vertical space use. Black prefers to split by operator if there's more than one, otherwise it leads to a myriad of pathological cases. We've tried always splitting on operators, it's less code actually. But testing with large bodies of source code, this wound up being worse on average.

I'm not closing this yet as I do feel we have tackle this somehow.

@felix-hilden
Copy link
Collaborator

Very much related to #2156 as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants