Skip to content

Commit af46450

Browse files
authored
Minor readability improvement for argument handling in itertools.repeat() (GH-17101)
1 parent e27449d commit af46450

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Modules/itertoolsmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,17 +4256,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
42564256
{
42574257
repeatobject *ro;
42584258
PyObject *element;
4259-
Py_ssize_t cnt = -1, n_kwds = 0;
4259+
Py_ssize_t cnt = -1, n_args;
42604260
static char *kwargs[] = {"object", "times", NULL};
42614261

4262+
n_args = PyTuple_GET_SIZE(args);
4263+
if (kwds != NULL)
4264+
n_args += PyDict_GET_SIZE(kwds);
42624265
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs,
42634266
&element, &cnt))
42644267
return NULL;
4265-
4266-
if (kwds != NULL)
4267-
n_kwds = PyDict_GET_SIZE(kwds);
42684268
/* Does user supply times argument? */
4269-
if ((PyTuple_Size(args) + n_kwds == 2) && cnt < 0)
4269+
if (n_args == 2 && cnt < 0)
42704270
cnt = 0;
42714271

42724272
ro = (repeatobject *)type->tp_alloc(type, 0);

0 commit comments

Comments
 (0)