summaryrefslogtreecommitdiffstats
path: root/Objects/funcobject.c
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2024-01-11 08:42:30 (GMT)
committerGitHub <noreply@github.com>2024-01-11 08:42:30 (GMT)
commit2ac4cf4743a65ac54c7ac6a762bed636800598fe (patch)
tree9845713b4a3055f7c0d4df968f18c254ca591855 /Objects/funcobject.c
parentf653caa5a88d3b5027a8f286ff3a3ccd9e6fe4ed (diff)
downloadcpython-2ac4cf4743a65ac54c7ac6a762bed636800598fe.zip
cpython-2ac4cf4743a65ac54c7ac6a762bed636800598fe.tar.gz
cpython-2ac4cf4743a65ac54c7ac6a762bed636800598fe.tar.bz2
gh-112640: Add `kwdefaults` parameter to `types.FunctionType.__new__` (#112641)
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r--Objects/funcobject.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 4d88dd2..2620dc6 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -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;
}