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

Regression: Unnecessary parens with unary minus operator #1041

Closed
JelleZijlstra opened this issue Oct 3, 2019 · 3 comments
Closed

Regression: Unnecessary parens with unary minus operator #1041

JelleZijlstra opened this issue Oct 3, 2019 · 3 comments

Comments

@JelleZijlstra
Copy link
Collaborator

I noticed this change while testing Black master on our codebase:

             step_adjustments["ScalingAdjustment"] = min(
-                scaling_adjustment, -self.get_max_weight()
+                scaling_adjustment, -(self.get_max_weight())
             )

Also (more justifiable):

-        -2 ** 32,
-        -2 ** 48,
-        -2 ** 63,
+        -(2 ** 32),
+        -(2 ** 48),
+        -(2 ** 63),

I think the first example is a bug. A simpler repro:

$ black -c '-self.x()'
-(self.x())

JelleZijlstra added a commit to JelleZijlstra/black that referenced this issue Oct 20, 2019
@hugovk
Copy link
Contributor

hugovk commented Oct 21, 2019

A few other examples, running master on a pre-Blackened codebase:

-        for y in range(-1, -im1.size[1] - 1, -1):
-            for x in range(-1, -im1.size[0] - 1, -1):
+        for y in range(-1, -(im1.size[1]) - 1, -1):
+            for x in range(-1, -(im1.size[0]) - 1, -1):
-        angle = -math.radians(deg)
+        angle = -(math.radians(deg))
         matrix = [
             round(math.cos(angle), 15),
             round(math.sin(angle), 15),
             0.0,
-            round(-math.sin(angle), 15),
+            round(-(math.sin(angle)), 15),
             round(math.cos(angle), 15),
             0.0,
             0,
-        code, = struct.unpack_from("<I", block, 12)
+        (code,) = struct.unpack_from("<I", block, 12)
-        angle = -math.radians(angle)
+        angle = -(math.radians(angle))
         matrix = [
             round(math.cos(angle), 15),
             round(math.sin(angle), 15),
             0.0,
-            round(-math.sin(angle), 15),
+            round(-(math.sin(angle)), 15),
-                dest[tag], = values
+                (dest[tag],) = values

With some comment mangling:

         if self.magic == b"BLP1":
-            # Only present for BLP1
-            self._blp_encoding, = struct.unpack("<i", self.fp.read(4))
-            self._blp_subtype, = struct.unpack("<i", self.fp.read(4))
+            (self._blp_encoding,) = struct.unpack(  # Only present for BLP1
+                "<i", self.fp.read(4)
+            )
+            (self._blp_subtype,) = struct.unpack("<i", self.fp.read(4))

@JelleZijlstra
Copy link
Collaborator Author

That last one looks like a separate regression. It doesn't make sense for Black to move that comment.

@JelleZijlstra
Copy link
Collaborator Author

Also, the tuple unpacking thing (your (code,) = example) is an intentional change from #832.

@ambv ambv closed this as completed in 6dca527 Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants