Make sure async for
is not broken up to separate lines (#503)
Fixes #372.
This commit is contained in:
parent
25795c9ff5
commit
08f1cdd00b
@ -872,6 +872,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
|
|||||||
|
|
||||||
* fixed formatting of lambda expressions with default arguments (#468)
|
* fixed formatting of lambda expressions with default arguments (#468)
|
||||||
|
|
||||||
|
* *Black* no longer breaks ``async for`` statements up to separate lines (#372)
|
||||||
|
|
||||||
|
|
||||||
### 18.6b4
|
### 18.6b4
|
||||||
|
|
||||||
|
11
black.py
11
black.py
@ -1889,7 +1889,7 @@ def is_split_after_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
|||||||
|
|
||||||
|
|
||||||
def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
||||||
"""Return the priority of the `leaf` delimiter, given a line before after it.
|
"""Return the priority of the `leaf` delimiter, given a line break before it.
|
||||||
|
|
||||||
The delimiter priorities returned here are from those delimiters that would
|
The delimiter priorities returned here are from those delimiters that would
|
||||||
cause a line break before themselves.
|
cause a line break before themselves.
|
||||||
@ -1926,15 +1926,20 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
|
|||||||
):
|
):
|
||||||
return STRING_PRIORITY
|
return STRING_PRIORITY
|
||||||
|
|
||||||
if leaf.type != token.NAME:
|
if leaf.type not in {token.NAME, token.ASYNC}:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if (
|
if (
|
||||||
leaf.value == "for"
|
leaf.value == "for"
|
||||||
and leaf.parent
|
and leaf.parent
|
||||||
and leaf.parent.type in {syms.comp_for, syms.old_comp_for}
|
and leaf.parent.type in {syms.comp_for, syms.old_comp_for}
|
||||||
|
or leaf.type == token.ASYNC
|
||||||
):
|
):
|
||||||
return COMPREHENSION_PRIORITY
|
if (
|
||||||
|
not isinstance(leaf.prev_sibling, Leaf)
|
||||||
|
or leaf.prev_sibling.value != "async"
|
||||||
|
):
|
||||||
|
return COMPREHENSION_PRIORITY
|
||||||
|
|
||||||
if (
|
if (
|
||||||
leaf.value == "if"
|
leaf.value == "if"
|
||||||
|
@ -3,6 +3,17 @@
|
|||||||
def f():
|
def f():
|
||||||
return (i*2 async for i in arange(42))
|
return (i*2 async for i in arange(42))
|
||||||
|
|
||||||
|
def g():
|
||||||
|
return (something_long * something_long async for something_long in async_generator(with_an_argument))
|
||||||
|
|
||||||
|
async def func():
|
||||||
|
if test:
|
||||||
|
out_batched = [
|
||||||
|
i
|
||||||
|
async for i in aitertools._async_map(
|
||||||
|
self.async_inc, arange(8), batch_size=3
|
||||||
|
)
|
||||||
|
]
|
||||||
# output
|
# output
|
||||||
|
|
||||||
|
|
||||||
@ -11,3 +22,20 @@ def f():
|
|||||||
|
|
||||||
def f():
|
def f():
|
||||||
return (i * 2 async for i in arange(42))
|
return (i * 2 async for i in arange(42))
|
||||||
|
|
||||||
|
|
||||||
|
def g():
|
||||||
|
return (
|
||||||
|
something_long * something_long
|
||||||
|
async for something_long in async_generator(with_an_argument)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def func():
|
||||||
|
if test:
|
||||||
|
out_batched = [
|
||||||
|
i
|
||||||
|
async for i in aitertools._async_map(
|
||||||
|
self.async_inc, arange(8), batch_size=3
|
||||||
|
)
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user