diff options
author | Raymond Hettinger <python@rcn.com> | 2014-06-25 04:36:58 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2014-06-25 04:36:58 (GMT) |
commit | 97d3555029b02fa4b432c1a1259b64aaa31e4e3e (patch) | |
tree | b986e1e25c2184d7c53b6cdb16e30487c3a7c733 /Modules/itertoolsmodule.c | |
parent | ca5c7153de0e14052483676b2cdf6791f1eeb7d2 (diff) | |
download | cpython-97d3555029b02fa4b432c1a1259b64aaa31e4e3e.zip cpython-97d3555029b02fa4b432c1a1259b64aaa31e4e3e.tar.gz cpython-97d3555029b02fa4b432c1a1259b64aaa31e4e3e.tar.bz2 |
Issue #19145: Fix handling of negative values for a "times" keyword argument to itertools.repeat()>
(Patch contributed by Vajrasky Kok.)
Diffstat (limited to 'Modules/itertoolsmodule.c')
-rw-r--r-- | Modules/itertoolsmodule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index cec1f87..ae5b166 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -4109,14 +4109,17 @@ repeat_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { repeatobject *ro; PyObject *element; - Py_ssize_t cnt = -1; + Py_ssize_t cnt = -1, n_kwds = 0; static char *kwargs[] = {"object", "times", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs, &element, &cnt)) return NULL; - if (PyTuple_Size(args) == 2 && cnt < 0) + if (kwds != NULL) + n_kwds = PyDict_Size(kwds); + /* Does user supply times argument? */ + if ((PyTuple_Size(args) + n_kwds == 2) && cnt < 0) cnt = 0; ro = (repeatobject *)type->tp_alloc(type, 0); |