diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4090,15 +4090,23 @@ { repeatobject *ro; PyObject *element; + PyObject *count_object = Py_None; Py_ssize_t cnt = -1; static char *kwargs[] = {"object", "times", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs, - &element, &cnt)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:repeat", kwargs, + &element, &count_object)) return NULL; - if (PyTuple_Size(args) == 2 && cnt < 0) - cnt = 0; + if (count_object == Py_None) + cnt = -1; + else { + cnt = PyLong_AsLong(count_object); + if ((cnt == -1) && PyErr_Occurred()) + return NULL; + if (cnt < 0) + cnt = 0; + } ro = (repeatobject *)type->tp_alloc(type, 0); if (ro == NULL)