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

Incorrect Space Added after Assignment Expression in If Statement #1174

Closed
t-mart opened this issue Nov 23, 2019 · 1 comment · Fixed by #1655
Closed

Incorrect Space Added after Assignment Expression in If Statement #1174

t-mart opened this issue Nov 23, 2019 · 1 comment · Fixed by #1655
Labels
T: bug Something isn't working

Comments

@t-mart
Copy link

t-mart commented Nov 23, 2019

Description
Black on the current master@c53853f and (19.10b0) adds a space after Assignment Expressions and before the final colon in if statements.

For what it's worth, I'm not sure if this is actually intended behavior or not, but it doesn't seem like it. No other parenthesized expressions in if statements get this treatment.

To Reproduce:

  1. Put this example in a file:
    if (foo := True):
        print(foo)
  2. Run black <file> --diff

Expected behavior
Black should not need to act upon this file. There should be no diff output and black should claim 1 file would be left unchanged.

Actual behavior
Black currently inserts a space between the end of the assignment expression and the colon.

Actual black <file> --diff output:

--- blacktest.py        2019-11-23 00:56:09.070688 +0000
+++ blacktest.py        2019-11-23 00:56:15.282759 +0000
@@ -1,3 +1,3 @@
-if (foo := True):
+if (foo := True) :
     print(foo)

Environment:

Does this bug also happen on master?
Yes

Other Information
This also affects if statements that are broken up into several lines.

The following example comes come a current project, excuse the specificity. The # pylint: disable=superfluous-parens should be treated simply as a comment for the scope of this issue. (In reality, pylint is also currently having a problem with assignment expressions)

class Foo:
    def method(self):
        if (
            invalid_reasons := self.invalid_reasons()
        ):  # pylint: disable=superfluous-parens
            LOGGER.error(
                f"Not saving raid for the following reasons: {', '.join(invalid_reasons)}"
            )
            return
--- blacktest.py        2019-11-23 01:07:27.116369 +0000
+++ blacktest.py        2019-11-23 01:07:30.956945 +0000
@@ -1,10 +1,10 @@
 class Foo:
     def method(self):
         if (
             invalid_reasons := self.invalid_reasons()
-        ):  # pylint: disable=superfluous-parens
+        ) :  # pylint: disable=superfluous-parens
             LOGGER.error(
                 f"Not saving raid for the following reasons: {', '.join(invalid_reasons)}"
             )
             return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants