Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dae2ef1

Browse files
committed
merge 3.4
2 parents 43e3d22 + 65bcdd7 commit dae2ef1

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/test/test_functools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ def test_kw_combinations(self):
7777
# exercise special code paths for no keyword args in
7878
# either the partial object or the caller
7979
p = self.partial(capture)
80+
self.assertEqual(p.keywords, {})
8081
self.assertEqual(p(), ((), {}))
8182
self.assertEqual(p(a=1), ((), {'a':1}))
8283
p = self.partial(capture, a=1)
84+
self.assertEqual(p.keywords, {'a':1})
8385
self.assertEqual(p(), ((), {'a':1}))
8486
self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
8587
# keyword args in the call override those in the partial object

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ Library
167167
lines from the code object, fixing an issue when a lambda function is used as
168168
decorator argument. Patch by Thomas Ballinger and Allison Kaptur.
169169

170+
- The keywords attribute of functools.partial is now always a dictionary.
171+
170172
- Issue #23811: Add missing newline to the PyCompileError error message.
171173
Patch by Alex Shkop.
172174

Modules/_functoolsmodule.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,17 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
102102
}
103103
}
104104
else {
105-
pto->kw = pkw;
106-
Py_INCREF(pkw);
105+
if (pkw == Py_None) {
106+
pto->kw = PyDict_New();
107+
if (pto->kw == NULL) {
108+
Py_DECREF(pto);
109+
return NULL;
110+
}
111+
}
112+
else {
113+
pto->kw = pkw;
114+
Py_INCREF(pkw);
115+
}
107116
}
108117

109118
pto->weakreflist = NULL;

0 commit comments

Comments
 (0)