[Python-checkins] cpython (merge 3.4 -> default): merge 3.4

benjamin.peterson python-checkins at python.org
Sat May 9 06:29:12 CEST 2015


https://hg.python.org/cpython/rev/73c79edc7f40
changeset:   95930:73c79edc7f40
parent:      95927:987b30a88653
parent:      95929:9dfda4e7169a
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat May 09 00:29:08 2015 -0400
summary:
  merge 3.4

files:
  Lib/test/test_functools.py |   2 ++
  Misc/NEWS                  |   2 ++
  Modules/_functoolsmodule.c |  13 +++++++++++--
  3 files changed, 15 insertions(+), 2 deletions(-)


diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -77,9 +77,11 @@
         # 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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -167,6 +167,8 @@
   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
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -102,8 +102,17 @@
         }
     }
     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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list