Skip to content

Trailing comma is not deleted in a one-line dict literal #2052

@Wim-De-Clercq

Description

@Wim-De-Clercq

Describe the style change
When a specific dict with callables gets the key looked up and the callable called in one go, the formatting is both uglier than the original and also invalid for flake8.

Examples in the current Black style
Before formatting:

value = "1"
key = "integer"

x = {
    "string": str,
    "integer": int,
}[key](value)

After formatting:

value = "1"
key = "integer"

x = {"string": str, "integer": int,}[
    key
](value)

This is not valid for flake8, and looks worse than what it was.

Desired style

value = "1"
key = "integer"

x = {
    "string": str,
    "integer": int,
}[key](value)

Or perhaps

value = "1"
key = "integer"

x = {"string": str, "integer": int}[key](value)

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: trailing commaFull of magicT: 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