[pypy-svn] pypy psycopg2compatibility: Added preliminary support for PySequence_DelItem() and test.

ademan commits-noreply at bitbucket.org
Thu Dec 23 09:18:06 CET 2010


Author: Daniel Roberts <Ademan555 at gmail.com>
Branch: psycopg2compatibility
Changeset: r40191:55c27ac06657
Date: 2010-12-23 00:13 -0800
http://bitbucket.org/pypy/pypy/changeset/55c27ac06657/

Log:	Added preliminary support for PySequence_DelItem() and test.

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
@@ -1965,15 +1965,6 @@
     changes in your code for properly supporting 64-bit systems."""
     raise NotImplementedError
 
- at cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
-def PySequence_DelItem(space, o, i):
-    """Delete the ith element of object o.  Returns -1 on failure.  This is the
-    equivalent of the Python statement del o[i].
-    
-    This function used an int type for i. This might require
-    changes in your code for properly supporting 64-bit systems."""
-    raise NotImplementedError
-
 @cpython_api([PyObject, PyObject], Py_ssize_t, error=-1)
 def PySequence_Count(space, o, value):
     """Return the number of occurrences of value in o, that is, return the number

diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -145,9 +145,19 @@
     
     This function used an int type for i. This might require
     changes in your code for properly supporting 64-bit systems."""
-
     if PyDict_Check(space, w_o) or not PySequence_Check(space, w_o):
         raise operationerrfmt(space.w_TypeError, "'%s' object does not support item assignment",
                              space.str_w(space.repr(space.type(w_o)))) # FIXME: looks like lisp...
     space.setitem(w_o, space.wrap(i), w_v)
     return 0
+
+ at cpython_api([PyObject, Py_ssize_t], rffi.INT_real, error=-1)
+def PySequence_DelItem(space, w_o, i):
+    """Delete the ith element of object o.  Returns -1 on failure.  This is the
+    equivalent of the Python statement del o[i].
+    
+    This function used an int type for i. This might require
+    changes in your code for properly supporting 64-bit systems."""
+
+    # FIXME: May be too lenient
+    space.delitem(w_o, space.wrap(i))

diff --git a/pypy/module/cpyext/test/test_sequence.py b/pypy/module/cpyext/test/test_sequence.py
--- a/pypy/module/cpyext/test/test_sequence.py
+++ b/pypy/module/cpyext/test/test_sequence.py
@@ -95,3 +95,14 @@
 
         self.raises(space, api, TypeError, api.PySequence_SetItem,
                     space.newdict(), 0, w_value)
+
+    def test_delitem(self, space, api):
+        w_l = space.wrap([1, 2, 3, 4])
+
+        result = api.PySequence_DelItem(w_l, 2)
+        assert result != -1
+        assert space.eq_w(w_l, space.wrap([1, 2, 4])
+
+        self.raises(space, api, IndexError, api.PySequence_DelItem,
+                    w_l, 3)
+        


More information about the Pypy-commit mailing list