bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem() by serhiy-storchaka · Pull Request #11112 · python/cpython
if (index < 0 || index >= self->groups) { /* raise IndexError if we were given a bad group number */ PyErr_SetString( PyExc_IndexError, "no such group" ); return NULL; }
assert(0 <= index && index < self->groups); index *= 2;
if (self->string == Py_None || self->mark[index] < 0) {
if (PyIndex_Check(index)) { return PyNumber_AsSsize_t(index, NULL); i = PyNumber_AsSsize_t(index, NULL); } else { i = -1;
i = -1;
if (self->pattern->groupindex) { index = PyDict_GetItem(self->pattern->groupindex, index); if (index && PyLong_Check(index)) { i = PyLong_AsSsize_t(index); if (self->pattern->groupindex) { index = PyDict_GetItemWithError(self->pattern->groupindex, index); if (index && PyLong_Check(index)) { i = PyLong_AsSsize_t(index); } } } if (i < 0 || i >= self->groups) { /* raise IndexError if we were given a bad group number */ if (!PyErr_Occurred()) { PyErr_SetString(PyExc_IndexError, "no such group"); } return -1; }
return i; }
static PyObject* match_getslice(MatchObject* self, PyObject* index, PyObject* def) { return match_getslice_by_index(self, match_getindex(self, index), def); Py_ssize_t i = match_getindex(self, index);
if (i < 0) { return NULL; }
return match_getslice_by_index(self, i, def); }
/*[clinic input]
if (index < 0 || index >= self->groups) { PyErr_SetString( PyExc_IndexError, "no such group" ); if (index < 0) { return -1; }
if (index < 0 || index >= self->groups) { PyErr_SetString( PyExc_IndexError, "no such group" ); if (index < 0) { return -1; }
if (index < 0 || index >= self->groups) { PyErr_SetString( PyExc_IndexError, "no such group" ); if (index < 0) { return NULL; }