[Python-checkins] cpython (2.7): ensure .keywords is always a dict

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


https://hg.python.org/cpython/rev/d6f6eded80d8
changeset: 95928:d6f6eded80d8
branch: 2.7
parent: 95924:96a7b401d5e4
user: Benjamin Peterson <benjamin at python.org>
date: Sat May 09 00:23:41 2015 -0400
summary:
 ensure .keywords is always a dict
files:
 Lib/test/test_functools.py | 2 ++
 Misc/NEWS | 2 ++
 Modules/_functoolsmodule.c | 14 +++++---------
 3 files changed, 9 insertions(+), 9 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
@@ -89,9 +89,11 @@
 # 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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@
 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.
 
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -132,17 +132,13 @@
 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;
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /