]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

fix unary op detection (#1600)
authorDavid Szotten <davidszotten@gmail.com>
Fri, 14 Aug 2020 16:17:56 +0000 (17:17 +0100)
committerGitHub <noreply@github.com>
Fri, 14 Aug 2020 16:17:56 +0000 (09:17 -0700)
src/black/__init__.py
tests/data/percent_precedence.py

index b660e4788b496fd36e7868dca308a35dcf60c63d..391233ed4485e16dc6798c2d041412dd8c5e1c82 100644 (file)
@@ -3297,12 +3297,12 @@ class StringParenStripper(StringTransformer):
             # if the leaves in the parsed string include a PERCENT, we need to
             # make sure the initial LPAR is NOT preceded by an operator with
             # higher or equal precedence to PERCENT
-            if (
-                is_valid_index(idx - 2)
-                and token.PERCENT in {leaf.type for leaf in LL[idx - 1 : next_idx]}
-                and (
+            if is_valid_index(idx - 2):
+                # mypy can't quite follow unless we name this
+                before_lpar = LL[idx - 2]
+                if token.PERCENT in {leaf.type for leaf in LL[idx - 1 : next_idx]} and (
                     (
-                        LL[idx - 2].type
+                        before_lpar.type
                         in {
                             token.STAR,
                             token.AT,
@@ -3318,12 +3318,12 @@ class StringParenStripper(StringTransformer):
                     )
                     or (
                         # only unary PLUS/MINUS
-                        not is_valid_index(idx - 3)
-                        and (LL[idx - 2].type in {token.PLUS, token.MINUS})
+                        before_lpar.parent
+                        and before_lpar.parent.type == syms.factor
+                        and (before_lpar.type in {token.PLUS, token.MINUS})
                     )
-                )
-            ):
-                continue
+                ):
+                    continue
 
             # Should be followed by a non-empty RPAR...
             if (
index 44d30f16e03b184dbbf00a34afd1c85956849300..b895443fb46bbf372727bef666a1c3e23deaa536 100644 (file)
@@ -12,6 +12,7 @@
 b + ("" % a)
 -("" % a)
 b - ("" % a)
+b + -("" % a)
 ~("" % a)
 2 ** ("" % a)
 await ("" % a)
@@ -32,6 +33,7 @@ b(("" % a))
 b + "" % a
 -("" % a)
 b - "" % a
+b + -("" % a)
 ~("" % a)
 2 ** ("" % a)
 await ("" % a)