]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
ensure .keywords is always a dict
authorBenjamin Peterson <benjamin@python.org>
Sat, 9 May 2015 04:25:18 +0000 (00:25 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sat, 9 May 2015 04:25:18 +0000 (00:25 -0400)
Lib/test/test_functools.py
Misc/NEWS
Modules/_functoolsmodule.c

index 0375601c518cebf8986b2189410840edea77efa5..36f154a7f568c7765ba3e1c19492335c99c62777 100644 (file)
@@ -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
index d01f52533f006c03351a98b553f838a1a05ea057..e2f749c42c2d5b692c1b6beb51e839a7d247f902 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -57,6 +57,8 @@ Library
 - Issue #9246: On POSIX, os.getcwd() now supports paths longer than 1025 bytes.
   Patch written by William Orr.
 
+- The keywords attribute of functools.partial is now always a dictionary.
+
 - Issues #24099, #24100, and #24101: Fix free-after-use bug in heapq's siftup
   and siftdown functions.
 
index 57dfba041013b82ce0b4fa8ec2a013e2663ad41b..24da67741b841ff2ac71cb11564f2f2f19daee7b 100644 (file)
@@ -54,17 +54,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;