Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 61730) +++ Objects/typeobject.c (working copy) @@ -4878,7 +4878,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__ is removed. Use __getitem__.", + 2) < 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) @@ -4903,13 +4915,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__ is removed. Use __delitem__.", + 2) < 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__ is removed. Use __setitem__.", + 2) < 0) + return -1; + res = call_method(self, "__setslice__", &setslice_str, "(nnO)", i, j, value); + } if (res == NULL) return -1; Py_DECREF(res); Index: Lib/test/test_py3kwarn.py =================================================================== --- Lib/test/test_py3kwarn.py (revision 61730) +++ Lib/test/test_py3kwarn.py (working copy) @@ -117,6 +117,25 @@ 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 + obj = Spam() + + expected = "In 3.x, __getslice__ is removed. Use __getitem__." + with catch_warning() as w: + self.assertWarning(obj[1:2], w, expected) + expected = "In 3.x, __delslice__ is removed. Use __delitem__." + with catch_warning() as w: + del obj[3:4] + self.assertWarning(None, w, expected) + expected = "In 3.x, __setslice__ is removed. Use __setitem__." + with catch_warning() as w: + obj[4:5] = "eggs" + self.assertWarning(None, w, expected) def test_main():