bpo-29800: Fix crashes in partial.__repr__ if the keys of partial.keywords are not strings (#649) (#671)
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 7abc9f4..1bcf16a 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -250,8 +250,11 @@
/* Pack keyword arguments */
assert (PyDict_Check(pto->kw));
for (i = 0; PyDict_Next(pto->kw, &i, &key, &value);) {
- Py_SETREF(arglist, PyUnicode_FromFormat("%U, %U=%R", arglist,
+ /* Prevent key.__str__ from deleting the value. */
+ Py_INCREF(value);
+ Py_SETREF(arglist, PyUnicode_FromFormat("%U, %S=%R", arglist,
key, value));
+ Py_DECREF(value);
if (arglist == NULL)
goto done;
}