]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minor readability improvement for argument handling in itertools.repeat() (GH-17101)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sun, 10 Nov 2019 04:28:31 +0000 (20:28 -0800)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2019 04:28:31 +0000 (20:28 -0800)
Modules/itertoolsmodule.c

index 3d39fa2e4737bd4fa52ad4013ed8ba2d786d3d74..0cb472966d1f950bcf67065fffce98bfe810886b 100644 (file)
@@ -4256,17 +4256,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
     repeatobject *ro;
     PyObject *element;
-    Py_ssize_t cnt = -1, n_kwds = 0;
+    Py_ssize_t cnt = -1, n_args;
     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,
                                      &element, &cnt))
         return NULL;
-
-    if (kwds != NULL)
-        n_kwds = PyDict_GET_SIZE(kwds);
     /* Does user supply times argument? */
-    if ((PyTuple_Size(args) + n_kwds == 2) && cnt < 0)
+    if (n_args == 2 && cnt < 0)
         cnt = 0;
 
     ro = (repeatobject *)type->tp_alloc(type, 0);