Skip to content

Prefer expanding RHS of item assignment over LHS #1498

@ghost

Description

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,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions