Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r92434:5dd50480d9b7
Date: 2017-09-22 02:35 +0100
http://bitbucket.org/pypy/pypy/changeset/5dd50480d9b7/

Log:    Add async slots to built-in types

diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -442,7 +442,10 @@
 
     handled = False
     # unary functions
-    for tp_name, attr in [('tp_as_number.c_nb_int', '__int__'),
+    for tp_name, attr in [('tp_as_async.c_am_await', '__await__'),
+                          ('tp_as_async.c_am_anext', '__anext__'),
+                          ('tp_as_async.c_am_aiter', '__aiter__'),
+                          ('tp_as_number.c_nb_int', '__int__'),
                           ('tp_as_number.c_nb_long', '__long__'),
                           ('tp_as_number.c_nb_float', '__float__'),
                           ('tp_as_number.c_nb_negative', '__neg__'),
diff --git a/pypy/module/cpyext/test/test_genobject.py 
b/pypy/module/cpyext/test/test_genobject.py
--- a/pypy/module/cpyext/test/test_genobject.py
+++ b/pypy/module/cpyext/test/test_genobject.py
@@ -1,3 +1,4 @@
+from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.genobject import PyGen_Check, PyGen_CheckExact
 from pypy.module.cpyext.genobject import PyCoro_CheckExact
@@ -25,3 +26,21 @@
         assert not PyGen_Check(space, w_coroutine)
         assert not PyGen_CheckExact(space, w_coroutine)
         assert PyCoro_CheckExact(space, w_coroutine)
+
+class AppTestCoroutine(AppTestCpythonExtensionBase):
+    def test_simple(self):
+        """
+        module = self.import_extension('test_coroutine', [
+            ('await_', 'METH_O',
+             '''
+             PyAsyncMethods* am = args->ob_type->tp_as_async;
+             if (am && am->am_await) {
+                return am->am_await(args);
+             }
+             PyErr_SetString(PyExc_TypeError, "Not an awaitable");
+             return NULL;
+             '''),])
+        async def f():
+            pass
+        raises(StopIteration, next, module.await_(f()))
+        """
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to