[pypy-commit] pypy default: PyGen_Check(), PyGen_CheckExact()

arigo pypy.commits at gmail.com
Sun Feb 5 11:53:49 EST 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r89944:7a5c63c2feec
Date: 2017-02-05 17:52 +0100
http://bitbucket.org/pypy/pypy/changeset/7a5c63c2feec/

Log:	PyGen_Check(), PyGen_CheckExact()

diff --git a/pypy/module/cpyext/genobject.py b/pypy/module/cpyext/genobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/genobject.py
@@ -0,0 +1,5 @@
+from pypy.interpreter.generator import GeneratorIterator
+from pypy.module.cpyext.api import build_type_checkers
+
+
+PyGen_Check, PyGen_CheckExact = build_type_checkers("Gen", GeneratorIterator)
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -695,17 +695,6 @@
     extension modules."""
     raise NotImplementedError
 
- at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyGen_Check(space, ob):
-    """Return true if ob is a generator object; ob must not be NULL."""
-    raise NotImplementedError
-
- at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyGen_CheckExact(space, ob):
-    """Return true if ob's type is PyGen_Type is a generator object; ob must not
-    be NULL."""
-    raise NotImplementedError
-
 @cpython_api([PyFrameObject], PyObject)
 def PyGen_New(space, frame):
     """Create and return a new generator object based on the frame object. A
diff --git a/pypy/module/cpyext/test/test_genobject.py b/pypy/module/cpyext/test/test_genobject.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/test_genobject.py
@@ -0,0 +1,15 @@
+from pypy.module.cpyext.test.test_api import BaseApiTest
+from pypy.module.cpyext.genobject import PyGen_Check, PyGen_CheckExact
+
+
+class TestGenObject(BaseApiTest):
+    def test_genobject(self, space):
+        w_geniter = space.appexec([], """():
+            def f():
+                yield 42
+            return f()
+        """)
+        assert PyGen_Check(space, w_geniter)
+        assert PyGen_CheckExact(space, w_geniter)
+        assert not PyGen_Check(space, space.wrap(2))
+        assert not PyGen_CheckExact(space, space.wrap("b"))


More information about the pypy-commit mailing list