[pypy-svn] r73200 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

benjamin at codespeak.net benjamin at codespeak.net
Wed Mar 31 03:20:48 CEST 2010


Author: benjamin
Date: Wed Mar 31 03:20:46 2010
New Revision: 73200

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
Log:
implement PyDict_CheckExact and add tests

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/dictobject.py	Wed Mar 31 03:20:46 2010
@@ -1,6 +1,6 @@
 from pypy.rpython.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import cpython_api, PyObject, CANNOT_FAIL, \
-    general_check, register_container
+    general_check, general_check_exact, register_container
 from pypy.module.cpyext.pyerrors import PyErr_BadInternalCall
 from pypy.interpreter.error import OperationError
 
@@ -13,6 +13,11 @@
     w_type = space.w_dict
     return general_check(space, w_obj, w_type)
 
+ at cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyDict_CheckExact(space, w_obj):
+    w_type = space.w_dict
+    return general_check_exact(space, w_obj, w_type)
+
 @cpython_api([PyObject, PyObject], PyObject)
 def PyDict_GetItem(space, w_dict, w_key):
     if PyDict_Check(space, w_dict):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_dictobject.py	Wed Mar 31 03:20:46 2010
@@ -21,3 +21,18 @@
         assert not api.PyDict_GetItem(d, space.wrap("name"))
         assert api.PyErr_Occurred() is space.w_KeyError
         api.PyErr_Clear()
+
+    def test_check(self, space, api):
+        d = api.PyDict_New()
+        assert api.PyDict_Check(d)
+        assert api.PyDict_CheckExact(d)
+        sub = space.appexec([], """():
+            class D(dict):
+                pass
+            return D""")
+        d = space.call_function(sub)
+        assert api.PyDict_Check(d)
+        assert not api.PyDict_CheckExact(d)
+        i = space.wrap(2)
+        assert not api.PyDict_Check(i)
+        assert not api.PyDict_CheckExact(i)



More information about the Pypy-commit mailing list