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

Redundant parentheses around string/int literals #1123

Open
wimglenn opened this issue Oct 30, 2019 · 6 comments
Open

Redundant parentheses around string/int literals #1123

wimglenn opened this issue Oct 30, 2019 · 6 comments
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like?

Comments

@wimglenn
Copy link

wimglenn commented Oct 30, 2019

Black could remove redundant parens from keyword arguments
Playground link here

Blackened style

foo(x=("hello"))
foo(x=(1))

Desired style

foo(x="hello")
foo(x=1)

I get this a lot when black has reformatted a multi line string which was using implicit concatenation all onto one line. It doesn't actually join the strings (OK, I understand the reason for that) but when you manually delete quotes to join them yourself, you are gonna get redundant parens hanging around.

@wimglenn wimglenn added the T: style What do we want Blackened code to look like? label Oct 30, 2019
@JelleZijlstra
Copy link
Collaborator

I tried doing this before the last release but unfortunately it caused some issues, so I had to revert. See #1079.

@astier
Copy link

astier commented Jan 17, 2020

Can confirm. Would be really helpful.

@bbugyi200
Copy link
Contributor

#1132 fixes this for strings, but not the foo(x=(1)) case.

@ichard26
Copy link
Collaborator

Another example (from #1151, a duplicate of this issue):

foo(a=1, **{"b": 2} if bar() else {}, c=3)
foo(a=1, **({"b": 2} if bar() else {}), c=3)

@ichard26 ichard26 added the F: parentheses Too many parentheses, not enough parentheses, and so on. label May 30, 2021
@Akuli
Copy link

Akuli commented Jun 5, 2021

Not fixed for strings yet #2307 assert foo == ("Blah blah blah. Blah.")

@bbugyi200
Copy link
Contributor

bbugyi200 commented Jun 5, 2021

Not fixed for strings yet #2307 assert foo == ("Blah blah blah. Blah.")

@Akuli This was fixed by #1132, but this PR has been masked with a feature flag (--experimental-string-processing):

image

Note that there is an effort to eventually enable this feature by default (see #2188) once all of the kinks have been worked out.

@JelleZijlstra JelleZijlstra changed the title Black doesn't remove redundant parens Redundant parentheses around string/int literals Jan 29, 2022
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. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

6 participants