diff --git a/src_c/pixelarray.c b/src_c/pixelarray.c index 53c32a41f5..f13c604553 100644 --- a/src_c/pixelarray.c +++ b/src_c/pixelarray.c @@ -1666,15 +1666,9 @@ _pxarray_subscript(pgPixelArrayObject *array, PyObject *op) return _pxarray_subscript_internal(array, start, stop, step, 0, dim1, 1); } - else if (PyIndex_Check(op) || PyLong_Check(op)) { - Py_ssize_t i; - PyObject *val = PyNumber_Index(op); - if (!val) { - return 0; - } + else if (PyIndex_Check(op)) { /* A simple index. */ - i = PyNumber_AsSsize_t(val, PyExc_IndexError); - Py_DECREF(val); + Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { return 0; } @@ -1828,15 +1822,9 @@ _pxarray_ass_subscript(pgPixelArrayObject *array, PyObject *op, Py_DECREF(tmparray); return retval; } - else if (PyIndex_Check(op) || PyLong_Check(op)) { - Py_ssize_t i; - PyObject *val = PyNumber_Index(op); - if (!val) { - return -1; - } + else if (PyIndex_Check(op)) { /* A simple index. */ - i = PyNumber_AsSsize_t(val, PyExc_IndexError); - Py_DECREF(val); + Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { return -1; } diff --git a/src_c/rect_impl.h b/src_c/rect_impl.h index 3f4084ff9c..0deafbcef4 100644 --- a/src_c/rect_impl.h +++ b/src_c/rect_impl.h @@ -2160,14 +2160,7 @@ RectExport_subscript(RectObject *self, PyObject *op) PrimitiveType *data = (PrimitiveType *)&self->r; if (PyIndex_Check(op)) { - PyObject *index = PyNumber_Index(op); - Py_ssize_t i; - - if (index == NULL) { - return NULL; - } - i = PyNumber_AsSsize_t(index, NULL); - Py_DECREF(index); + Py_ssize_t i = PyNumber_AsSsize_t(op, NULL); return RectExport_item(self, i); } else if (op == Py_Ellipsis) { @@ -2213,15 +2206,7 @@ RectExport_assSubscript(RectObject *self, PyObject *op, PyObject *value) return -1; } if (PyIndex_Check(op)) { - PyObject *index; - Py_ssize_t i; - - index = PyNumber_Index(op); - if (index == NULL) { - return -1; - } - i = PyNumber_AsSsize_t(index, NULL); - Py_DECREF(index); + Py_ssize_t i = PyNumber_AsSsize_t(op, NULL); return RectExport_assItem(self, i, value); } else if (op == Py_Ellipsis) {