Author: Raffael Tfirst <[email protected]>
Branch: py3.5-async
Changeset: r86243:7d96e4bc57bb
Date: 2016-08-17 13:04 +0200
http://bitbucket.org/pypy/pypy/changeset/7d96e4bc57bb/
Log: Add StopAsyncIteration exception, expand test to check 'async for'
in test_asyncio
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
@@ -619,7 +619,7 @@
self.emit_jump(ops.JUMP_FORWARD, b_after_try)
self.use_next_block(b_except)
self.emit_op(ops.POP_TOP)
- self.emit_op_name(ops.LOAD_GLOBAL, self.names, "StopIterError")
+ self.emit_op_name(ops.LOAD_GLOBAL, self.names, "StopAsyncIteration")
self.emit_op_arg(ops.COMPARE_OP, 10)
self.emit_jump(ops.POP_JUMP_IF_FALSE, b_try_cleanup, True)
diff --git a/pypy/module/_asyncio/test/test_asyncio.py
b/pypy/module/_asyncio/test/test_asyncio.py
--- a/pypy/module/_asyncio/test/test_asyncio.py
+++ b/pypy/module/_asyncio/test/test_asyncio.py
@@ -1,4 +1,5 @@
class AppTestAsyncIO(object):
+ """These tests are based on the async-await syntax of Python 3.5."""
spaceconfig = dict(usemodules=["select","_socket","thread","signal",
"struct","_multiprocessing","array",
@@ -9,14 +10,19 @@
# the problem occured at await asyncio.open_connection
# after calling run_until_complete
"""
- import encodings.idna
- import asyncio
- async def f():
- reader, writer = await asyncio.open_connection('example.com', 80)
-
- loop = asyncio.get_event_loop()
- loop.run_until_complete(f())
- print("done with async loop")
+import encodings.idna
+import asyncio
+
+async def f():
+ reader, writer = await asyncio.open_connection('example.com', 80)
+ writer.write(b'a')
+ async for line in reader:
+ print('>>>', line)
+ writer.close()
+
+loop = asyncio.get_event_loop()
+loop.run_until_complete(f())
+print("done with async loop")
"""
def test_asynchronous_context_managers(self):
diff --git a/pypy/module/exceptions/__init__.py
b/pypy/module/exceptions/__init__.py
--- a/pypy/module/exceptions/__init__.py
+++ b/pypy/module/exceptions/__init__.py
@@ -51,6 +51,7 @@
'ResourceWarning' : 'interp_exceptions.W_ResourceWarning',
'RuntimeError' : 'interp_exceptions.W_RuntimeError',
'RuntimeWarning' : 'interp_exceptions.W_RuntimeWarning',
+ 'StopAsyncIteration' : 'interp_exceptions.W_StopAsyncIteration',
'StopIteration' : 'interp_exceptions.W_StopIteration',
'SyntaxError' : 'interp_exceptions.W_SyntaxError',
'SyntaxWarning' : 'interp_exceptions.W_SyntaxWarning',
diff --git a/pypy/module/exceptions/interp_exceptions.py
b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -64,6 +64,7 @@
+-- ReferenceError
+-- RuntimeError
| +-- NotImplementedError
+ +-- StopAsyncIteration
+-- SyntaxError
| +-- IndentationError
| +-- TabError
@@ -833,6 +834,9 @@
W_AssertionError = _new_exception('AssertionError', W_Exception,
"""Assertion failed.""")
+W_StopAsyncIteration = _new_exception('StopAsyncIteration', W_Exception,
+ """Signal the end from
iterator.__anext__().""")
+
class W_UnicodeDecodeError(W_UnicodeError):
"""Unicode decoding error."""
w_encoding = None
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit