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.
This commit is contained in:
parent
a73d25883a
commit
14b28c89c2
20
black.py
20
black.py
@ -1714,26 +1714,6 @@ def visit_default(self, node: LN) -> Iterator[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:
|
||||
|
||||
|
@ -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))
|
||||
|
@ -424,7 +424,7 @@ async def f():
|
||||
{"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))
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user