mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
builtin_apply(): Second argument type check is relaxed to allow any sequence.
This commit is contained in:
parent
566373e974
commit
968f8cbace
1 changed files with 18 additions and 6 deletions
|
@ -101,20 +101,32 @@ builtin_apply(self, args)
|
||||||
PyObject *args;
|
PyObject *args;
|
||||||
{
|
{
|
||||||
PyObject *func, *alist = NULL, *kwdict = NULL;
|
PyObject *func, *alist = NULL, *kwdict = NULL;
|
||||||
|
PyObject *t = NULL, *retval = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O|OO:apply", &func, &alist, &kwdict))
|
if (!PyArg_ParseTuple(args, "O|OO:apply", &func, &alist, &kwdict))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (alist != NULL && !PyTuple_Check(alist)) {
|
if (alist != NULL) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
if (!PyTuple_Check(alist)) {
|
||||||
"apply() 2nd argument must be tuple");
|
if (!PySequence_Check(alist)) {
|
||||||
return NULL;
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
"apply() 2nd argument must be a sequence");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
t = PySequence_Tuple(alist);
|
||||||
|
if (t == NULL)
|
||||||
|
return NULL;
|
||||||
|
alist = t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (kwdict != NULL && !PyDict_Check(kwdict)) {
|
if (kwdict != NULL && !PyDict_Check(kwdict)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"apply() 3rd argument must be dictionary");
|
"apply() 3rd argument must be dictionary");
|
||||||
return NULL;
|
goto finally;
|
||||||
}
|
}
|
||||||
return PyEval_CallObjectWithKeywords(func, alist, kwdict);
|
retval = PyEval_CallObjectWithKeywords(func, alist, kwdict);
|
||||||
|
finally:
|
||||||
|
Py_XDECREF(t);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char apply_doc[] =
|
static char apply_doc[] =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue