[pypy-commit] pypy py3.6: Test and fix async generator with 'await' in 'finally' block.
mjacob
pypy.commits at gmail.com
Sat Mar 31 14:38:17 EDT 2018
Author: Manuel Jacob <me at manueljacob.de>
Branch: py3.6
Changeset: r94205:252f070e9c1a
Date: 2018-03-31 20:17 +0200
http://bitbucket.org/pypy/pypy/changeset/252f070e9c1a/
Log: Test and fix async generator with 'await' in 'finally' block.
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -718,7 +718,7 @@
# TODO: add equivalent to CPython's o->agt_gen->ag_closed = 1;
w_value = self.async_gen.throw(space.w_GeneratorExit,
None, None)
- if w_value is not None:
+ if w_value is not None and isinstance(w_value, AsyncGenValueWrapper):
raise oefmt(space.w_RuntimeError,
"async generator ignored GeneratorExit")
else:
diff --git a/pypy/interpreter/test/test_coroutine.py b/pypy/interpreter/test/test_coroutine.py
--- a/pypy/interpreter/test/test_coroutine.py
+++ b/pypy/interpreter/test/test_coroutine.py
@@ -504,6 +504,39 @@
raises(RuntimeError, run().send, None)
"""
+ def test_async_aclose_await_in_finally(self): """
+ import types
+
+ @types.coroutine
+ def coro():
+ yield 'coro'
+
+ state = 0
+ async def ag():
+ nonlocal state
+ try:
+ yield
+ finally:
+ state = 1
+ await coro()
+ state = 2
+
+ async def run():
+ a = ag()
+ async for i in a:
+ break
+ await a.aclose()
+ a = run()
+ assert state == 0
+ assert a.send(None) == 'coro'
+ assert state == 1
+ try:
+ a.send(None)
+ except StopIteration:
+ pass
+ assert state == 2
+ """
+
def test_async_anext_close(self): """
async def ag():
yield 42
More information about the pypy-commit
mailing list