]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Make sure `async for` is not broken up to separate lines (#503)
authorZsolt Dollenstein <zsol.zsol@gmail.com>
Sat, 8 Sep 2018 09:34:08 +0000 (10:34 +0100)
committerGitHub <noreply@github.com>
Sat, 8 Sep 2018 09:34:08 +0000 (10:34 +0100)
Fixes #372.

README.md
black.py
tests/data/python37.py

index 9d156fbf605032b71ba9209a2f16f81627e757d5..d50b13d44132dc2bccd532522293a9e586f5ba76 100644 (file)
--- a/README.md
+++ b/README.md
@@ -872,6 +872,8 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
 
 * fixed formatting of lambda expressions with default arguments (#468)
 
+* *Black* no longer breaks ``async for`` statements up to separate lines (#372)
+
 
 ### 18.6b4
 
index 3a51f21f4cd16b22e63a76918e4e46709f680316..6f7496ede2345e597c3b3145fc268d65c8f7b416 100644 (file)
--- a/black.py
+++ b/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:
-    """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
     cause a line break before themselves.
@@ -1926,15 +1926,20 @@ def is_split_before_delimiter(leaf: Leaf, previous: Leaf = None) -> int:
     ):
         return STRING_PRIORITY
 
-    if leaf.type != token.NAME:
+    if leaf.type not in {token.NAME, token.ASYNC}:
         return 0
 
     if (
         leaf.value == "for"
         and leaf.parent
         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 (
         leaf.value == "if"
index ae20ade097dc4a4226174d588188575a9e66672d..9781ff6391158773a32fbdd0906bc44cd4a423c6 100644 (file)
@@ -3,6 +3,17 @@
 def f():
     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
 
 
@@ -11,3 +22,20 @@ def f():
 
 def f():
     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
+            )
+        ]