[pypy-commit] pypy py3.7: support async generator expressions in normal functions
cfbolz
pypy.commits at gmail.com
Thu Jan 23 06:02:22 EST 2020
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.7
Changeset: r98573:bde40d73c3de
Date: 2020-01-23 12:01 +0100
http://bitbucket.org/pypy/pypy/changeset/bde40d73c3de/
Log: support async generator expressions in normal functions
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1569,10 +1569,6 @@
code, qualname = self.sub_scope(sub_scope, name, node, node.lineno)
is_async_generator = self.symbols.find_scope(node).is_coroutine
- if is_async_generator and not is_async_function:
- self.error("asynchronous comprehension outside of "
- "an asynchronous function", node)
-
self.update_position(node.lineno)
self._make_function(code, qualname=qualname)
first_comp = node.get_generators()[0]
diff --git a/pypy/interpreter/test/apptest_coroutine.py b/pypy/interpreter/test/apptest_coroutine.py
--- a/pypy/interpreter/test/apptest_coroutine.py
+++ b/pypy/interpreter/test/apptest_coroutine.py
@@ -699,6 +699,20 @@
assert run_async(run()) == ([], (1,))
+def test_async_genexpr_in_regular_function():
+ async def arange(n):
+ for i in range(n):
+ yield i
+
+ def make_arange(n):
+ # This syntax is legal starting with Python 3.7
+ return (i * 2 async for i in arange(n))
+
+ async def run():
+ return [i async for i in make_arange(10)]
+ res = run_async(run())
+ assert res[1] == [i * 2 for i in range(10)]
+
# Helpers for test_async_gen_exception_11() below
def sync_iterate(g):
res = []
More information about the pypy-commit
mailing list