X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/7d213c6d4364a1bc3886f3253a7417c7b36f01a3..b073c9a4e956f0e350394b7b164cac25801256d7:/black.py diff --git a/black.py b/black.py index 97393e1..779e9d0 100644 --- 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.