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

jandem at codespeak.net jandem at codespeak.net
Sat Apr 10 13:17:02 CEST 2010


Author: jandem
Date: Sat Apr 10 13:17:01 2010
New Revision: 73609

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/object.py
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
Log:
Add PyObject_Repr, with tests


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py	Sat Apr 10 13:17:01 2010
@@ -105,3 +105,10 @@
     op.c_ob_refcnt = 1
     return from_ref(space, rffi.cast(PyObject, op)) # XXX likewise
 
+ at cpython_api([PyObject], PyObject)
+def PyObject_Repr(space, w_obj):
+    """Compute a string representation of object o.  Returns the string
+    representation on success, NULL on failure.  This is the equivalent of the
+    Python expression repr(o).  Called by the repr() built-in function and
+    by reverse quotes."""
+    return space.repr(w_obj)

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_object.py	Sat Apr 10 13:17:01 2010
@@ -64,3 +64,7 @@
 
     def test_size(self, space, api):
         assert api.PyObject_Size(space.newlist([space.w_None])) == 1
+        
+    def test_repr(self, space, api):
+        w_list = space.newlist([space.w_None, space.wrap(42)])
+        assert space.str_w(api.PyObject_Repr(w_list)) == "[None, 42]"



More information about the Pypy-commit mailing list