Logged In: YES
user_id=80475
xrange() needs to be kept closely parallel with range() .
Accordingly, it should not sprout keyword arguments.
For all of these, I think the solution is to raise a
TypeError when keyword arguments are supplied to
functions/types that don't handle them.
Encapsulate the logic in a new internal API function:
int
_PyArg_NoKeywords(char *funcname, PyObject *kwds)
{
if (kwds == NULL) return 1;
if (!PyDict_CheckExact(kwds)){
bad internal call
return 0;
}
if (PyDict_Size(kwds) == 0)
return 1;
set_exc_typeerror(funcname does not take kw args)
return 0;
}
Then go through the code finding all the type constructors
(grep for PyTypeObject) and add the error check if the kwds
arg is being ignored). For example:
range_new(PyTypeObject *type, PyObject *args, PyObject *kw)
{
if (!_PyArg_NoKeywords("xrange", kw))
return NULL;
. . .
Be sure to add test cases for every constructor that gets
changed. Also, go ahead an backport to Py2.4.2. |