]> granicus.if.org Git - python/commitdiff
ensure .keywords is always a dict
authorBenjamin Peterson <benjamin@python.org>
Sat, 9 May 2015 04:23:41 +0000 (00:23 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sat, 9 May 2015 04:23:41 +0000 (00:23 -0400)
Lib/test/test_functools.py
Misc/NEWS
Modules/_functoolsmodule.c

index c0a9a3b8f53e7534205a84a7ef7ed2c18eec8592..7b3cb96497709740ea244b74f496675d4366ff7b 100644 (file)
@@ -89,9 +89,11 @@ class TestPartial(unittest.TestCase):
         # exercise special code paths for no keyword args in
         # either the partial object or the caller
         p = self.thetype(capture)
+        self.assertEqual(p.keywords, {})
         self.assertEqual(p(), ((), {}))
         self.assertEqual(p(a=1), ((), {'a':1}))
         p = self.thetype(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
index e76f18710c31e0fdaf6699da349cd13e75afe19a..b5a149c9b425fa2154bcba182ae3338a599e6c5f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@ Core and Builtins
 Library
 -------
 
+- The keywords attribute of functools.partial is now always a dictionary.
+
 - Issue #24134: assertRaises() and assertRaisesRegexp() checks are not longer
   successful if the callable is None.
 
index 6397ba951d4fec3234efb2283d5d4a89a29ef3a4..2ba92bae9d4fecb1d741ff6e885e6f08d0ec895c 100644 (file)
@@ -132,17 +132,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
         Py_DECREF(pto);
         return NULL;
     }
-    if (kw != NULL) {
-        pto->kw = PyDict_Copy(kw);
-        if (pto->kw == NULL) {
-            Py_DECREF(pto);
-            return NULL;
-        }
-    } else {
-        pto->kw = Py_None;
-        Py_INCREF(Py_None);
+    pto->kw = (kw != NULL) ? PyDict_Copy(kw) : PyDict_New();
+    if (pto->kw == NULL) {
+        Py_DECREF(pto);
+        return NULL;
     }
 
+
     pto->weakreflist = NULL;
     pto->dict = NULL;