Skip to content

Remove optional brackets around unpacking #3203

@TomFryers

Description

@TomFryers

Remove optional brackets around unpacking

Since #2945, Black removes brackets in the following situation:

for (x, y) in stuff:
    ...

Perhaps this should be extended to include unpacking assignments.
Examples in the current Black style

(x, y) = point
(first, *rest, last) = things
[a, b] = foo  # Not touched with for at the moment

Desired style

x, y = point
first, *rest, last = things
a, b = foo  # Not touched with for at the moment

Additional context

The current style is unstable in situations like the following:

x, y = loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
# Modify
x, y = reallyloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
# Blacken
(
    x,
    y,
) = reallyloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
# Try to revert
(
    x,
    y,
) = loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
# Blacken (with -C, or remove the trailing comma manually)
(x, y) = loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong

Metadata

Metadata

Assignees

Labels

F: parenthesesToo many parentheses, not enough parentheses, and so on.S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: 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