Message209440
| Author |
larry |
| Recipients |
BreamoreBoy, belopolsky, ezio.melotti, larry, rhettinger, serhiy.storchaka, terry.reedy, vajrasky |
| Date |
2014年01月27日.12:49:37 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1390826978.15.0.964476952273.issue19145@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|