Author: Armin Rigo <ar...@tunes.org> Branch: py3.5-corowrapper Changeset: r87201:b16d98337497 Date: 2016-09-17 23:15 +0200 http://bitbucket.org/pypy/pypy/changeset/b16d98337497/
Log: Comment, test about StopAsyncIteration diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -107,6 +107,9 @@ frame = self.frame if frame is None: if isinstance(self, Coroutine): + # NB. CPython checks a flag 'closing' here, but instead + # we can simply not be here at all if frame is None in + # this case raise oefmt(space.w_RuntimeError, "cannot reuse already awaited coroutine") # xxx a bit ad-hoc, but we don't want to go inside 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 @@ -32,6 +32,31 @@ assert False, "should have raised" """ + def test_StopAsyncIteration(self): """ + class X: + def __aiter__(self): + return MyAIter() + class MyAIter: + count = 0 + async def __anext__(self): + if self.count == 3: + raise StopAsyncIteration + self.count += 1 + return 42 + async def f(x): + sum = 0 + async for a in x: + sum += a + return sum + cr = f(X()) + try: + cr.send(None) + except StopIteration as e: + assert e.value == 42 * 3 + else: + assert False, "should have raised" + """ + def test_async_for_old_style(self): """ class X: def __aiter__(self): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit