[Python-checkins] CVS: python/dist/src/Objects descrobject.c,2.17,2.18 typeobject.c,2.111,2.112
Guido van Rossum
gvanrossum@users.sourceforge.net
Sun, 21 Oct 2001 17:43:46 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv21240/Objects
Modified Files:
descrobject.c typeobject.c
Log Message:
Methods of built-in types now properly check for keyword arguments
(formerly these were silently ignored). The only built-in methods
that take keyword arguments are __call__, __init__ and __new__.
Index: descrobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/descrobject.c,v
retrieving revision 2.17
retrieving revision 2.18
diff -C2 -d -r2.17 -r2.18
*** descrobject.c 2001/10/21 22:26:43 2.17
--- descrobject.c 2001/10/22 00:43:43 2.18
***************
*** 806,809 ****
--- 806,820 ----
PyObject *self = wp->self;
+ if (wp->descr->d_base->flags & PyWrapperFlag_KEYWORDS) {
+ wrapperfunc_kwds wk = (wrapperfunc_kwds)wrapper;
+ return (*wk)(self, args, wp->descr->d_wrapped, kwds);
+ }
+
+ if (kwds != NULL && (!PyDict_Check(kwds) || PyDict_Size(kwds) != 0)) {
+ PyErr_Format(PyExc_TypeError,
+ "wrapper %s doesn't take keyword arguments",
+ wp->descr->d_base->name);
+ return NULL;
+ }
return (*wrapper)(self, args, wp->descr->d_wrapped);
}
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.111
retrieving revision 2.112
diff -C2 -d -r2.111 -r2.112
*** typeobject.c 2001/10/21 22:28:58 2.111
--- typeobject.c 2001/10/22 00:43:43 2.112
***************
*** 2252,2261 ****
static PyObject *
! wrap_call(PyObject *self, PyObject *args, void *wrapped)
{
ternaryfunc func = (ternaryfunc)wrapped;
! /* XXX What about keyword arguments? */
! return (*func)(self, args, NULL);
}
--- 2252,2260 ----
static PyObject *
! wrap_call(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
{
ternaryfunc func = (ternaryfunc)wrapped;
! return (*func)(self, args, kwds);
}
***************
*** 2329,2338 ****
static PyObject *
! wrap_init(PyObject *self, PyObject *args, void *wrapped)
{
initproc func = (initproc)wrapped;
! /* XXX What about keyword arguments? */
! if (func(self, args, NULL) < 0)
return NULL;
Py_INCREF(Py_None);
--- 2328,2336 ----
static PyObject *
! wrap_init(PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
{
initproc func = (initproc)wrapped;
! if (func(self, args, kwds) < 0)
return NULL;
Py_INCREF(Py_None);
***************
*** 3178,3181 ****
--- 3176,3180 ----
#undef TPSLOT
+ #undef FLSLOT
#undef ETSLOT
#undef SQSLOT
***************
*** 3189,3192 ****
--- 3188,3194 ----
#define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
{NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, DOC}
+ #define FLSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, FLAGS) \
+ {NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
+ DOC, FLAGS}
#define ETSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC) \
{NAME, offsetof(etype, SLOT), (void *)(FUNCTION), WRAPPER, DOC}
***************
*** 3347,3352 ****
TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc,
"x.__hash__() <==> hash(x)"),
! TPSLOT("__call__", tp_call, slot_tp_call, wrap_call,
! "x.__call__(...) <==> x(...)"),
TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook,
wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"),
--- 3349,3354 ----
TPSLOT("__hash__", tp_hash, slot_tp_hash, wrap_hashfunc,
"x.__hash__() <==> hash(x)"),
! FLSLOT("__call__", tp_call, slot_tp_call, (wrapperfunc)wrap_call,
! "x.__call__(...) <==> x(...)", PyWrapperFlag_KEYWORDS),
TPSLOT("__getattribute__", tp_getattro, slot_tp_getattr_hook,
wrap_binaryfunc, "x.__getattribute__('name') <==> x.name"),
***************
*** 3380,3388 ****
TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set,
"descr.__set__(obj, value)"),
! TPSLOT("__init__", tp_init, slot_tp_init, wrap_init,
"x.__init__(...) initializes x; "
! "see x.__class__.__doc__ for signature"),
! TPSLOT("__new__", tp_new, slot_tp_new, NULL,
! ""),
{NULL}
};
--- 3382,3390 ----
TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set,
"descr.__set__(obj, value)"),
! FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)wrap_init,
"x.__init__(...) initializes x; "
! "see x.__class__.__doc__ for signature",
! PyWrapperFlag_KEYWORDS),
! TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""),
{NULL}
};