Skip to content

Black trims whitespace around walrus operators in slices #3820

@charliermarsh

Description

@charliermarsh

Describe the bug

Black trims whitespace around := operators within slices. I'm not sure if this is a feature or a bug (if it's intended, feel free to close of course).

The behavior is similar to Black's treatment of : operators in slices as described here, but I can't tell if the same treatment is intentional for := operators.

To Reproduce

For example, given this code:

x[y := 1]

The formatted code is:

x[y:=1]

Similar to treatment of the : operator, Black does not reformat these:

x[(y := 1)]
x[y := f()]

Here's a playground link to demonstrate the above cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions