[3.13] GH-141312: Allow only integers to longrangeiter_setstate state (GH-141317) (GH-141568)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c1eb)
This commit is contained in:
Sergey Miryanov 2025-11-16 00:14:17 +05:00 committed by GitHub
parent b693037040
commit cbeada9ec7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 0 deletions

View file

@ -1014,6 +1014,11 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
static PyObject *
longrangeiter_setstate(longrangeiterobject *r, PyObject *state)
{
if (!PyLong_CheckExact(state)) {
PyErr_Format(PyExc_TypeError, "state must be an int, not %T", state);
return NULL;
}
PyObject *zero = _PyLong_GetZero(); // borrowed reference
int cmp;