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

Prefer expanding RHS of item assignment over LHS #1498

Closed
ghost opened this issue Jun 15, 2020 · 1 comment · Fixed by #3368
Closed

Prefer expanding RHS of item assignment over LHS #1498

ghost opened this issue Jun 15, 2020 · 1 comment · Fixed by #3368
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@ghost
Copy link

ghost commented Jun 15, 2020

Hi guys, first of all thanks for this amazing tool! Glad to see it taking the Python world by storm.

This is a fairly minor style change request.

The formatting I take issue with occurs during item assignment. When the assignment exceeds the line length and the RHS has no "required" parentheses to break on, it chooses to break on the square brackets on the LHS of the assignment:

# CURRENT BEHAVIOUR
# in:

some_dictionary["some_key"] = some_long_expression_causing_long_line

# out:

some_dictionary[
    "some_key"
] = some_long_expression_causing_long_line

Personally I think this is really ugly - looking at this expression, it is not immediately obvious that an assignment is happening, since the = is moved to the 3rd line. Of all the non-blacked code I've ever read, not one line has ever been formatted like that, which tells me it's not totally human-friendly.

My desired result for the above input would be like the following:

# DESIRED BEHAVIOUR
some_dictionary["some_key"] = (
    some_long_expression_causing_long_line
)

Obviously for the cases where my desired behaviour would still result in the 1st line being longer than the desired line length, the current behaviour should be applied.

My current workaround for this styling caveat is to use dict.update() instead (though obviously this isn't a general solution since __setitem__ is not exclusive to MutableMappings):

some_dictionary.update(
    some_key=some_long_expression_causing_long_line,
)
@ghost ghost added the T: style What do we want Blackened code to look like? label Jun 15, 2020
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label May 30, 2021
@yilei
Copy link
Contributor

yilei commented Oct 31, 2022

FYI-- I'm working on a PR to make this change.

#445 (comment) mentions the same issue where the LHS is a tuple.

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

Successfully merging a pull request may close this issue.

2 participants