]> 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:

Force parentheses between unary op and binary power. (#909)
authorBrandt Bucher <brandtbucher@gmail.com>
Sat, 29 Jun 2019 16:35:16 +0000 (09:35 -0700)
committerJelle Zijlstra <jelle.zijlstra@gmail.com>
Sat, 29 Jun 2019 16:35:16 +0000 (09:35 -0700)
black.py
tests/data/expression.diff
tests/data/expression.py

index 97393e164005404ed76951f5612d8fcd1b45fb3c..779e9d0c873eafa31dc8a660e6c1311f5c13fcfb 100644 (file)
--- a/black.py
+++ b/black.py
@@ -1643,6 +1643,19 @@ class LineGenerator(Visitor[Line]):
             node.children[2].value = ""
         yield from super().visit_default(node)
 
+    def visit_factor(self, node: Node) -> Iterator[Line]:
+        """Force parentheses between a unary op and a binary power:
+
+        -2 ** 8 -> -(2 ** 8)
+        """
+        child = node.children[1]
+        if child.type == syms.power and len(child.children) == 3:
+            lpar = Leaf(token.LPAR, "(")
+            rpar = Leaf(token.RPAR, ")")
+            index = child.remove() or 0
+            node.insert_child(index, Node(syms.atom, [lpar, child, rpar]))
+        yield from self.visit_default(node)
+
     def visit_INDENT(self, node: Node) -> Iterator[Line]:
         """Increase indentation level, maybe yield a line."""
         # In blib2to3 INDENT never holds comments.
index 9e01f3fad37aa9b62282b4315a07d64ca7fb5599..c3ee14d7629c62be827519ac0e30b9ed0486ca76 100644 (file)
  True
  False
  1
-@@ -29,62 +29,83 @@
+@@ -29,63 +29,84 @@
  ~great
  +value
  -1
  ~int and not v1 ^ 123 + v2 | True
  (~int) and (not ((v1 ^ (123 + v2)) | True))
+-+really ** -confusing ** ~operator ** -precedence
 -flags & ~ select.EPOLLIN and waiters.write_task is not None
+++(really ** -(confusing ** ~(operator ** -precedence)))
 +flags & ~select.EPOLLIN and waiters.write_task is not None
  lambda arg: None
  lambda a=True: a
  call(**self.screen_kwargs)
  call(b, **self.screen_kwargs)
  lukasz.langa.pl
-@@ -93,23 +114,25 @@
+@@ -94,23 +115,25 @@
  1.0 .real
  ....__class__
  list[str]
  slice[0:1:2]
  slice[:]
  slice[:-1]
-@@ -133,113 +156,171 @@
+@@ -134,113 +157,171 @@
  numpy[-(c + 1) :, d]
  numpy[:, l[-2]]
  numpy[:, ::-1]
index a2fc5897e6de80ce6b5a7e79cf2ff6279ee55865..912f76d7bbb0037a4dafd61ae93f1c5cf3a1e570 100644 (file)
@@ -31,6 +31,7 @@ not great
 -1
 ~int and not v1 ^ 123 + v2 | True
 (~int) and (not ((v1 ^ (123 + v2)) | True))
++really ** -confusing ** ~operator ** -precedence
 flags & ~ select.EPOLLIN and waiters.write_task is not None
 lambda arg: None
 lambda a=True: a
@@ -280,6 +281,7 @@ not great
 -1
 ~int and not v1 ^ 123 + v2 | True
 (~int) and (not ((v1 ^ (123 + v2)) | True))
++(really ** -(confusing ** ~(operator ** -precedence)))
 flags & ~select.EPOLLIN and waiters.write_task is not None
 lambda arg: None
 lambda a=True: a