Skip to content

Trailing comma in a dict in function call split all parameters #2672

@char101

Description

@char101

Describe the style change

When passing dict as a function parameter I often prefer than the dict is split in multiple lines while keeping other parameters in the same line.

Original code:

db.insert('table', {'a': 10, 'b': 11})

Examples in the current Black style

Adding a trailing comma in the dict results in all parameters split, consuming 7 lines, which feel too excessive in the vertical space usage.

db.insert(
    'table',
    {
        'a': 10,
        'b': 11,
    },
)

Desired style

A more compact format could be this which only consumes 3 lines.

db.insert('table', {
    'a': 10,
    'b': 11,
})

Which is, black could only split the dictionary without affecting the function parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?T: styleWhat do we want Blackened code to look like?
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions