Skip to content

Prefer splitting expressions with many child expressions. #1811

@torotil

Description

@torotil

Describe the style change

Currently black splits lines from the outermost expression to the innermost expression. This makes sense in most cases, but there is some cases where preferring the inner expression is more semantic. This is especially true if the only argument of a function is a dictionary.

Examples in the current Black style

f(
    {
        "foo": "This is a dict",
        "bar": "with values that are too long",
        "baz": "to fit on a line.",
    }
)

Desired style

f({
   "foo": "This is a dict",
   "bar": "with values that are too long",
   "baz": "to fit on a line.",
})

In this example the first break (putting the dict on it’s own line) doesn’t even make the lines any shorter.

Additional context

It’s hard to make a general rule out of this. Perhaps splitting expressions first that have many child-expresssions would be a reasonable heuristic, but I’m happy for suggestions.

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