Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove optional brackets around unpacking #3203

Open
TomFryers opened this issue Aug 2, 2022 · 2 comments
Open

Remove optional brackets around unpacking #3203

TomFryers opened this issue Aug 2, 2022 · 2 comments
Assignees
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?

Comments

@TomFryers
Copy link
Contributor

TomFryers commented Aug 2, 2022

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
@TomFryers TomFryers added the T: style What do we want Blackened code to look like? label Aug 2, 2022
@ichard26
Copy link
Collaborator

ichard26 commented Aug 2, 2022

I agree, cross-linking with #3080.

@ichard26 ichard26 added F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented labels Aug 2, 2022
@ichard26 ichard26 added this to the Release 22.8.0 milestone Aug 2, 2022
@ichard26 ichard26 self-assigned this Aug 28, 2022
@ichard26 ichard26 removed this from the Release 22.9.0 milestone Sep 14, 2022
@johannesrld
Copy link

johannesrld commented Mar 22, 2023

this would be great to include, it can be quite annoying having code that looks like this:

version, = struct.unpack("<f", field.read(4))

into this

(version,) = struct.unpack("<f", field.read(4))

(edit: although im gonna assume that some people would think the former is less readable)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants