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

Black adds parens to long right tuples, it should add them to the left as well #336

Closed
virtuald opened this issue Jun 10, 2018 · 1 comment

Comments

@virtuald
Copy link

Referring to #330, I know you said you weren't going to fix this, but @sjohannes found a good solution that is very Blackish and IMHO worth considering.

Minimized Real Source ™️ :

from gi.repository import GtkTemplate

class Something:
    
    found_label,    \
    playlists,      \
    replace,        \
    replace_entry,  \
    search_entry,   \
    tracks_list = GtkTemplate.Child.widgets(6)

Which currently reformats to a really long ugly line:


from gi.repository import GtkTemplate


class Something:

    found_label, playlists, replace, replace_entry, search_entry, tracks_list = GtkTemplate.Child.widgets(
        6
    )

It turns out that if you add parentheses to the left tuple, it is (a) still equivalent and (b) black does the Right Thing. Here's what that looks like:

from gi.repository import GtkTemplate

class Something:
    
    (found_label,    \
    playlists,      \
    replace,        \
    replace_entry,  \
    search_entry,   \
    tracks_list) = GtkTemplate.Child.widgets(6)

And black does this:

from gi.repository import GtkTemplate


class Something:

    (
        found_label,
        playlists,
        replace,
        replace_entry,
        search_entry,
        tracks_list,
    ) = GtkTemplate.Child.widgets(6)

Which is a very Black style.

My request in this issue would be for black to add parentheses to the left tuple if it gets too long and format it as it currently does.

It can be shown that Black already does this for long tuples on the right side. It seems that for consistency it should apply the same style to tuples on the left as well.

@ambv
Copy link
Collaborator

ambv commented Jun 10, 2018

If you put the parentheses yourself, Black will keep them. That is a possible workaround for you. We won't be doing this by default since, as I said in the previous issue, your code will look more obvious if you do a mild refactor in that place.

I avoid splitting left-hand side of assignments since this is not how people write and read those things. When you first write code, you start on one line and keep going until you hit the column limit. When people read, this is what they instinctively do, too. A split that is too early looks foreign.

@ambv ambv closed this as completed Jun 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants