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

trailing space after parenthesized walrus operator #1522

Closed
xrisk opened this issue Jun 26, 2020 · 5 comments
Closed

trailing space after parenthesized walrus operator #1522

xrisk opened this issue Jun 26, 2020 · 5 comments
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@xrisk
Copy link
Contributor

xrisk commented Jun 26, 2020

Consider this snippet (as produced after running Black):

if (val := func()) :
    pass

Ideally, Black would remove the redundant parentheses (although I realize this is pretty hard to do).

However, why does Black insist on the single space before the terminating colon? This causes flake8 to complain (and rightly so I feel).

I skimmed through the PEP and I can’t seem to find any example where that space is used. Is this a deliberate design decision?

@xrisk xrisk added the T: style What do we want Blackened code to look like? label Jun 26, 2020
@xrisk
Copy link
Contributor Author

xrisk commented Jun 26, 2020

On closer reading through the PEP, I don’t see why (val := expr) shouldn’t be transformed into val := expr. They seem to be equivalent as far as I can tell (in the context of an if-conditional). The only cases where that transformation is not valid are in top-level statements and such.

@JelleZijlstra
Copy link
Collaborator

We definitely shouldn't put a space before the colon, that's a bug.

I'm not as sure we should remove the parentheses, maybe it's better for clarity to have them? Black is opinionated, but we should make sure we're opinionated in the right way.

@xrisk
Copy link
Contributor Author

xrisk commented Jun 28, 2020

@JelleZijlstra black does convert if (expr): to if expr: so…

And there are multiple examples in the PEP that omit the parentheses when there is no RHS.

@nixjdm
Copy link

nixjdm commented Aug 15, 2020

The title of this issue, which I'd take as the primary point of this issue, is a duplicate of #1174. I suggest closing this issue as a duplicate and opening a new issue just for discussing whether assignment expressions in ifs should be contained in parentheses.

@ichard26 ichard26 added T: bug Something isn't working R: duplicate This issue or pull request already exists and removed T: style What do we want Blackened code to look like? labels Aug 29, 2020
@ichard26
Copy link
Collaborator

The title of this issue, which I'd take as the primary point of this issue, is a duplicate of #1174. I suggest closing this issue as a duplicate and opening a new issue just for discussing whether assignment expressions in ifs should be contained in parentheses.

I agree and I've done that (see #1656). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants