Remove unnecessary parens around yield (#834)
This commit is contained in:
parent
c2c2f72038
commit
18119d3846
8
black.py
8
black.py
@ -2728,7 +2728,7 @@ def normalize_invisible_parens(node: Node, parens_after: Set[str]) -> None:
|
||||
for index, child in enumerate(list(node.children)):
|
||||
if check_lpar:
|
||||
if child.type == syms.atom:
|
||||
if maybe_make_parens_invisible_in_atom(child):
|
||||
if maybe_make_parens_invisible_in_atom(child, parent=node):
|
||||
lpar = Leaf(token.LPAR, "")
|
||||
rpar = Leaf(token.RPAR, "")
|
||||
index = child.remove() or 0
|
||||
@ -2839,7 +2839,7 @@ def generate_ignored_nodes(leaf: Leaf) -> Iterator[LN]:
|
||||
container = container.next_sibling
|
||||
|
||||
|
||||
def maybe_make_parens_invisible_in_atom(node: LN) -> bool:
|
||||
def maybe_make_parens_invisible_in_atom(node: LN, parent: LN) -> bool:
|
||||
"""If it's safe, make the parens in the atom `node` invisible, recursively.
|
||||
|
||||
Returns whether the node should itself be wrapped in invisible parentheses.
|
||||
@ -2849,7 +2849,7 @@ def maybe_make_parens_invisible_in_atom(node: LN) -> bool:
|
||||
node.type != syms.atom
|
||||
or is_empty_tuple(node)
|
||||
or is_one_tuple(node)
|
||||
or is_yield(node)
|
||||
or (is_yield(node) and parent.type != syms.expr_stmt)
|
||||
or max_delimiter_priority_in_atom(node) >= COMMA_PRIORITY
|
||||
):
|
||||
return False
|
||||
@ -2861,7 +2861,7 @@ def maybe_make_parens_invisible_in_atom(node: LN) -> bool:
|
||||
first.value = "" # type: ignore
|
||||
last.value = "" # type: ignore
|
||||
if len(node.children) > 1:
|
||||
maybe_make_parens_invisible_in_atom(node.children[1])
|
||||
maybe_make_parens_invisible_in_atom(node.children[1], parent=parent)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@ -147,7 +147,7 @@
|
||||
slice[0:1:2]
|
||||
slice[:]
|
||||
slice[:-1]
|
||||
@@ -133,111 +156,169 @@
|
||||
@@ -133,113 +156,171 @@
|
||||
numpy[-(c + 1) :, d]
|
||||
numpy[:, l[-2]]
|
||||
numpy[:, ::-1]
|
||||
@ -214,9 +214,14 @@
|
||||
+
|
||||
def gen():
|
||||
yield from outside_of_generator
|
||||
a = (yield)
|
||||
|
||||
- a = (yield)
|
||||
- b = ((yield))
|
||||
- c = (((yield)))
|
||||
+ a = yield
|
||||
+ b = yield
|
||||
+ c = yield
|
||||
+
|
||||
|
||||
async def f():
|
||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||
-print(* [] or [1])
|
||||
|
@ -169,6 +169,8 @@
|
||||
def gen():
|
||||
yield from outside_of_generator
|
||||
a = (yield)
|
||||
b = ((yield))
|
||||
c = (((yield)))
|
||||
|
||||
async def f():
|
||||
await some.complicated[0].call(with_args=(True or (1 is not 1)))
|
||||
@ -458,7 +460,9 @@ async def f():
|
||||
|
||||
def gen():
|
||||
yield from outside_of_generator
|
||||
a = (yield)
|
||||
a = yield
|
||||
b = yield
|
||||
c = yield
|
||||
|
||||
|
||||
async def f():
|
||||
|
Loading…
Reference in New Issue
Block a user