]> granicus.if.org Git - python/commitdiff
PyEval_CallObject requires a tuple of args (closes #13186)
authorBenjamin Peterson <benjamin@python.org>
Sat, 15 Oct 2011 17:43:21 +0000 (13:43 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sat, 15 Oct 2011 17:43:21 +0000 (13:43 -0400)
Lib/test/test_class.py
Misc/NEWS
Modules/_testcapimodule.c
Objects/classobject.c

index 0f2510182723414b59cc2163bfc0a785479cb60e..db75b934795155d3e1354908ab756c43f7b13617 100644 (file)
@@ -350,6 +350,19 @@ class ClassTests(unittest.TestCase):
         AllTests.__delslice__ = delslice
 
 
+    @test_support.cpython_only
+    def testDelItem(self):
+        class A:
+            ok = False
+            def __delitem__(self, key):
+                self.ok = True
+        a = A()
+        # Subtle: we need to call PySequence_SetItem, not PyMapping_SetItem.
+        from _testcapi import sequence_delitem
+        sequence_delitem(a, 2)
+        self.assertTrue(a.ok)
+
+
     def testUnaryOps(self):
         testme = AllTests()
 
index 03c4569acaeae783ed27ba9c33943564d3071e8e..6fdcc6f6ca0908203447e6d00d62b34201dad84f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@ What's New in Python 2.7.3?
 Core and Builtins
 -----------------
 
+- Issue #13186: Fix __delitem__ on old-style instances when invoked through
+  PySequence_DelItem.
+
 - Issue #13156: Revert the patch for issue #10517 (reset TLS upon fork()),
   which was only relevant for the native pthread TLS implementation.
 
index 23a569130476a21785ce3cbe30a574726c34da31..9c45274a70487e96df14ee909b712e1cddecc960 100644 (file)
@@ -1639,6 +1639,19 @@ make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
     return PyErr_NewExceptionWithDoc(name, doc, base, dict);
 }
 
+static PyObject *
+sequence_delitem(PyObject *self, PyObject *args)
+{
+    PyObject *seq;
+    Py_ssize_t i;
+
+    if (!PyArg_ParseTuple(args, "On", &seq, &i))
+        return NULL;
+    if (PySequence_DelItem(seq, i) < 0)
+        return NULL;
+    Py_RETURN_NONE;
+}
+
 static PyMethodDef TestMethods[] = {
     {"raise_exception",         raise_exception,                 METH_VARARGS},
     {"test_config",             (PyCFunction)test_config,        METH_NOARGS},
@@ -1695,6 +1708,7 @@ static PyMethodDef TestMethods[] = {
     {"code_newempty", code_newempty,                     METH_VARARGS},
     {"make_exception_with_doc", (PyCFunction)make_exception_with_doc,
      METH_VARARGS | METH_KEYWORDS},
+    {"sequence_delitem", (PyCFunction)sequence_delitem, METH_VARARGS},
     {NULL, NULL} /* sentinel */
 };
 
index 0832531422de83c2603ac99df66a849b59f7a405..161906ae5d19b32f30d5c6e89b22528a1922de18 100644 (file)
@@ -1221,7 +1221,7 @@ instance_ass_item(PyInstanceObject *inst, Py_ssize_t i, PyObject *item)
     if (func == NULL)
         return -1;
     if (item == NULL)
-        arg = PyInt_FromSsize_t(i);
+        arg = Py_BuildValue("(n)", i);
     else
         arg = Py_BuildValue("(nO)", i, item);
     if (arg == NULL) {