Message209440
For what it's worth: I figured out how this happened. Maybe it's obvious to you, but this behavior baffled me until I went back and looked at the revision history.
In revision e260d6daf784, the argument parsing for itertools.repeat looks like this:
Py_ssize_t cnt = -1;
if (type == &repeat_type && !_PyArg_NoKeywords("repeat()", kwds))
return NULL;
if (!PyArg_ParseTuple(args, "O|n:repeat", &element, &cnt))
return NULL;
if (PyTuple_Size(args) == 2 && cnt < 0)
cnt = 0;
In the subsequent revision, 3dbdbc5e6d85, it was changed to this:
Py_ssize_t cnt = -1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|n:repeat", kwargs,
&element, &cnt))
return NULL;
if (PyTuple_Size(args) == 2 && cnt < 0)
cnt = 0;
The original intent is now clear: only allow "cnt" to be -1 if it wasn't specified as an argument. The author simply forgot that "times" could now be passed in as a keyword argument too.
What the author *probably* wanted was something like this:
PyObject *times_keyword;
...
times_keyword = PyDict_GetItemString(kwargs, "times");
Py_XDECREF(times_keyword);
if ((PyTuple_Size(args) == 2 || times_keyword) && cnt < 0)
cnt = 0;
But I suggest it's far too late to change it to that now. |
|
Date |
User |
Action |
Args |
2014-01-27 12:49:38 | larry | set | recipients:
+ larry, rhettinger, terry.reedy, belopolsky, ezio.melotti, BreamoreBoy, serhiy.storchaka, vajrasky |
2014-01-27 12:49:38 | larry | set | messageid: <1390826978.15.0.964476952273.issue19145@psf.upfronthosting.co.za> |
2014-01-27 12:49:38 | larry | link | issue19145 messages |
2014-01-27 12:49:37 | larry | create | |
|