Message 24221 - Python tracker

Message24221

Author rhettinger
Recipients
Date 2005-08-25.14:35:07
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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.
History
Date User Action Args
2007-08-23 14:29:26adminlinkissue1119418 messages
2007-08-23 14:29:26admincreate