Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 63734) +++ Objects/typeobject.c (working copy) @@ -4881,7 +4881,19 @@ return NULL; } -SLOT2(slot_sq_slice, "__getslice__", Py_ssize_t, Py_ssize_t, "nn") +static PyObject* +slot_sq_slice(PyObject *self, Py_ssize_t i, Py_ssize_t j) +{ + static PyObject *getslice_str; + + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "In 3.x, __getslice__ has been removed. Use __getitem__.", + 1) < 0) + return NULL; + return call_method(self, "__getslice__", &getslice_str, + "nn", i, j); +} static int slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) @@ -4906,13 +4918,25 @@ { PyObject *res; static PyObject *delslice_str, *setslice_str; - - if (value == NULL) + + if (value == NULL) { + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "In 3.x, __delslice__ has been removed. Use __delitem__.", + 1) < 0) + return -1; res = call_method(self, "__delslice__", &delslice_str, "(nn)", i, j); - else - res = call_method(self, "__setslice__", &setslice_str, + } + else { + if (Py_Py3kWarningFlag && + PyErr_WarnEx(PyExc_DeprecationWarning, + "In 3.x, __setslice__ has been removed. Use __setitem__.", + 1) < 0) + return -1; + res = call_method(self, "__setslice__", &setslice_str, "(nnO)", i, j, value); + } if (res == NULL) return -1; Py_DECREF(res); Index: Objects/classobject.c =================================================================== --- Objects/classobject.c (revision 63734) +++ Objects/classobject.c (working copy) @@ -1174,8 +1174,14 @@ if (func == NULL) return NULL; arg = Py_BuildValue("(N)", _PySlice_FromIndices(i, j)); - } else + } else { + if (PyErr_WarnPy3k("In 3.x, __getslice__ has been removed. " + "Use __getitem__.", 1) < 0) { + Py_DECREF(func); + return NULL; + } arg = Py_BuildValue("(nn)", i, j); + } if (arg == NULL) { Py_DECREF(func); @@ -1257,8 +1263,14 @@ arg = Py_BuildValue("(N)", _PySlice_FromIndices(i, j)); - } else + } else { + if (PyErr_WarnPy3k("In 3.x, __delslice__ has been removed. " + "Use __delitem__.", 1) < 0) { + Py_DECREF(func); + return -1; + } arg = Py_BuildValue("(nn)", i, j); + } } else { if (setslicestr == NULL) { @@ -1284,8 +1296,14 @@ arg = Py_BuildValue("(NO)", _PySlice_FromIndices(i, j), value); - } else + } else { + if (PyErr_WarnPy3k("In 3.x, __setslice__ has been removed. " + "Use __setitem__.", 1) < 0) { + Py_DECREF(func); + return -1; + } arg = Py_BuildValue("(nnO)", i, j, value); + } } if (arg == NULL) { Py_DECREF(func); Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 63734) +++ Lib/test/test_py3kwarn.py (working copy) @@ -117,6 +117,32 @@ f.softspace = 0 with catch_warning() as w: self.assertWarning(set(), w, expected) + + def test_slice_methods(self): + class Spam(object): + def __getslice__(self, i, j): pass + def __setslice__(self, i, j, what): pass + def __delslice__(self, i, j): pass + class Egg: + def __getslice__(self, i, h): pass + def __setslice__(self, i, j, what): pass + def __delslice__(self, i, j): pass + + for obj in (Spam(), Egg()): + expected = "In 3.x, __getslice__ has been removed. " \ + "Use __getitem__." + with catch_warning() as w: + self.assertWarning(obj[1:2], w, expected) + expected = "In 3.x, __delslice__ has been removed. " \ + "Use __delitem__." + with catch_warning() as w: + del obj[3:4] + self.assertWarning(None, w, expected) + expected = "In 3.x, __setslice__ has been removed. " \ + "Use __setitem__." + with catch_warning() as w: + obj[4:5] = "eggs" + self.assertWarning(None, w, expected) def test_buffer(self): expected = 'buffer() not supported in 3.x; use memoryview()'