gh-125028: Prohibit placeholders in partial keywords (GH-126062)

This commit is contained in:
dgpb 2025-05-08 10:53:53 +03:00 committed by GitHub
parent 4fcd377563
commit afed5f8835
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 2 deletions

View file

@ -196,6 +196,19 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
return NULL;
}
/* keyword Placeholder prohibition */
if (kw != NULL) {
PyObject *key, *val;
Py_ssize_t pos = 0;
while (PyDict_Next(kw, &pos, &key, &val)) {
if (val == phold) {
PyErr_SetString(PyExc_TypeError,
"Placeholder cannot be passed as a keyword argument");
return NULL;
}
}
}
/* check wrapped function / object */
pto_args = pto_kw = NULL;
int res = PyObject_TypeCheck(func, state->partial_type);