From: Jelle Zijlstra Date: Sun, 20 Oct 2019 16:02:17 +0000 (-0700) Subject: Back out #850 (#1079) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/14b28c89c22659e1f935bc0ac22ee03d90bcc290?ds=inline;hp=a73d25883aaaa3fa3a10ea2ddfcb70ac1efd448e Back out #850 (#1079) Fixes #1042 (and probably #1044 which looks like the same thing). The issue with the "obviously unnecessary" parentheses that #850 removed is that sometimes they're necessary to help Black fit something in one line. I didn't see an obvious solution that still removes the parens #850 was intended to remove, so let's back out this change for now in the interest of unblocking a release. This PR also adds a test adapted from the failing example in #1042, so that if we try to reapply the #850 change we don't break the same case again. --- diff --git a/black.py b/black.py index 3842be9..151c1a6 100644 --- a/black.py +++ b/black.py @@ -1714,26 +1714,6 @@ class LineGenerator(Visitor[Line]): self.current_line.append(node) yield from super().visit_default(node) - def visit_atom(self, node: Node) -> Iterator[Line]: - # Always make parentheses invisible around a single node, because it should - # not be needed (except in the case of yield, where removing the parentheses - # produces a SyntaxError). - if ( - len(node.children) == 3 - and isinstance(node.children[0], Leaf) - and node.children[0].type == token.LPAR - and isinstance(node.children[2], Leaf) - and node.children[2].type == token.RPAR - and isinstance(node.children[1], Leaf) - and not ( - node.children[1].type == token.NAME - and node.children[1].value == "yield" - ) - ): - node.children[0].value = "" - 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: diff --git a/tests/data/expression.diff b/tests/data/expression.diff index da20094..629e101 100644 --- a/tests/data/expression.diff +++ b/tests/data/expression.diff @@ -171,8 +171,7 @@ +{"2.7": dead, "3.7": long_live or die_hard} +{"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"} [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C] --(SomeName) -+SomeName + (SomeName) SomeName (Good, Bad, Ugly) (i for i in (1, 2, 3)) diff --git a/tests/data/expression.py b/tests/data/expression.py index c9b149f..3bcf52b 100644 --- a/tests/data/expression.py +++ b/tests/data/expression.py @@ -424,7 +424,7 @@ numpy[np.newaxis, :] {"2.7": dead, "3.7": long_live or die_hard} {"2.7", "3.6", "3.7", "3.8", "3.9", "4.0" if gilectomy else "3.10"} [1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or A, 11 or B, 12 or C] -SomeName +(SomeName) SomeName (Good, Bad, Ugly) (i for i in (1, 2, 3)) diff --git a/tests/data/remove_parens.py b/tests/data/remove_parens.py index e128f59..afc3401 100644 --- a/tests/data/remove_parens.py +++ b/tests/data/remove_parens.py @@ -1,8 +1,19 @@ -print((1)) x = (1) x = (1.2) -(x) = (3) +data = ( + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +).encode() + +async def show_status(): + while True: + try: + if report_host: + data = ( + f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ).encode() + except Exception as e: + pass def example(): return (("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")) @@ -45,10 +56,23 @@ def example8(): # output -print(1) x = 1 x = 1.2 -x = 3 + +data = ( + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" +).encode() + + +async def show_status(): + while True: + try: + if report_host: + data = ( + f"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ).encode() + except Exception as e: + pass def example():