Minor readability improvement for argument handling in itertools.repeat() (GH-17101)

This commit is contained in:
Raymond Hettinger 2019-11-09 20:28:31 -08:00 committed by GitHub
parent e27449da92
commit af46450bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -4256,17 +4256,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
repeatobject *ro; repeatobject *ro;
PyObject *element; PyObject *element;
Py_ssize_t cnt = -1, n_kwds = 0; Py_ssize_t cnt = -1, n_args;
static char *kwargs[] = {"object", "times", NULL}; static char *kwargs[] = {"object", "times", NULL};
n_args = PyTuple_GET_SIZE(args);
if (kwds != NULL)
n_args += PyDict_GET_SIZE(kwds);
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs, if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs,
&element, &cnt)) &element, &cnt))
return NULL; return NULL;
if (kwds != NULL)
n_kwds = PyDict_GET_SIZE(kwds);
/* Does user supply times argument? */ /* Does user supply times argument? */
if ((PyTuple_Size(args) + n_kwds == 2) && cnt < 0) if (n_args == 2 && cnt < 0)
cnt = 0; cnt = 0;
ro = (repeatobject *)type->tp_alloc(type, 0); ro = (repeatobject *)type->tp_alloc(type, 0);