mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-112640: Add kwdefaults
parameter to types.FunctionType.__new__
(#112641)
This commit is contained in:
parent
f653caa5a8
commit
2ac4cf4743
8 changed files with 76 additions and 13 deletions
|
@ -809,14 +809,17 @@ function.__new__ as func_new
|
|||
a tuple that specifies the default argument values
|
||||
closure: object = None
|
||||
a tuple that supplies the bindings for free variables
|
||||
kwdefaults: object = None
|
||||
a dictionary that specifies the default keyword argument values
|
||||
|
||||
Create a function object.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
|
||||
PyObject *name, PyObject *defaults, PyObject *closure)
|
||||
/*[clinic end generated code: output=99c6d9da3a24e3be input=93611752fc2daf11]*/
|
||||
PyObject *name, PyObject *defaults, PyObject *closure,
|
||||
PyObject *kwdefaults)
|
||||
/*[clinic end generated code: output=de72f4c22ac57144 input=20c9c9f04ad2d3f2]*/
|
||||
{
|
||||
PyFunctionObject *newfunc;
|
||||
Py_ssize_t nclosure;
|
||||
|
@ -843,6 +846,11 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
if (kwdefaults != Py_None && !PyDict_Check(kwdefaults)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"arg 6 (kwdefaults) must be None or dict");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* check that the closure is well-formed */
|
||||
nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
|
||||
|
@ -879,6 +887,9 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals,
|
|||
if (closure != Py_None) {
|
||||
newfunc->func_closure = Py_NewRef(closure);
|
||||
}
|
||||
if (kwdefaults != Py_None) {
|
||||
newfunc->func_kwdefaults = Py_NewRef(kwdefaults);
|
||||
}
|
||||
|
||||
return (PyObject *)newfunc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue