Skip to content

Commit 561ca80

Browse files
authored
Document why functools.partial() must copy kwargs (#253)
Add a comment to prevent further attempts to avoid a copy for optimization.
1 parent 324c5d8 commit 561ca80

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Modules/_functoolsmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kw)
163163
Py_XINCREF(kwappl);
164164
}
165165
else {
166+
/* bpo-27840, bpo-29318: dictionary of keyword parameters must be
167+
copied, because a function using "**kwargs" can modify the
168+
dictionary. */
166169
kwappl = PyDict_Copy(pto->kw);
167170
if (kwappl == NULL) {
168171
Py_XDECREF(argappl);

Objects/call.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ _PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs,
317317
if (nk != 0) {
318318
Py_ssize_t pos, i;
319319

320-
/* Issue #29318: Caller and callee functions must not share the
321-
dictionary: kwargs must be copied. */
320+
/* bpo-29318, bpo-27840: Caller and callee functions must not share
321+
the dictionary: kwargs must be copied. */
322322
kwtuple = PyTuple_New(2 * nk);
323323
if (kwtuple == NULL) {
324324
return NULL;

0 commit comments

Comments
 (0)