summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-05-09 00:29:08 -0400
committerBenjamin Peterson <benjamin@python.org>2015-05-09 00:29:08 -0400
commitdae2ef1cfad60b149370b4012aa48bea2dd27445 (patch)
tree693595202f70ed00e60b57381cc4f76e6c7b9b61
parent43e3d22fee9b22f6f9dec4364ea4ee796faefaab (diff)
parent65bcdd7195666e20eb56a7d49b5dd0ee2278e506 (diff)
downloadcpython-git-dae2ef1cfad60b149370b4012aa48bea2dd27445.tar.gz
merge 3.4
-rw-r--r--Lib/test/test_functools.py2
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/_functoolsmodule.c13
3 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index e7f34cc721..03dd545736 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -77,9 +77,11 @@ class TestPartial:
# exercise special code paths for no keyword args in
# either the partial object or the caller
p = self.partial(capture)
+ self.assertEqual(p.keywords, {})
self.assertEqual(p(), ((), {}))
self.assertEqual(p(a=1), ((), {'a':1}))
p = self.partial(capture, a=1)
+ self.assertEqual(p.keywords, {'a':1})
self.assertEqual(p(), ((), {'a':1}))
self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
# keyword args in the call override those in the partial object
diff --git a/Misc/NEWS b/Misc/NEWS
index 782bc698b9..13dd8c30bc 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -167,6 +167,8 @@ Library
lines from the code object, fixing an issue when a lambda function is used as
decorator argument. Patch by Thomas Ballinger and Allison Kaptur.
+- The keywords attribute of functools.partial is now always a dictionary.
+
- Issue #23811: Add missing newline to the PyCompileError error message.
Patch by Alex Shkop.
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 3413b12dfe..3c82e5134a 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -102,8 +102,17 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
}
else {
- pto->kw = pkw;
- Py_INCREF(pkw);
+ if (pkw == Py_None) {
+ pto->kw = PyDict_New();
+ if (pto->kw == NULL) {
+ Py_DECREF(pto);
+ return NULL;
+ }
+ }
+ else {
+ pto->kw = pkw;
+ Py_INCREF(pkw);
+ }
}
pto->weakreflist = NULL;