ensure .keywords is always a dict

This commit is contained in:
Benjamin Peterson 2015-05-09 00:23:41 -04:00
parent 36691efe7b
commit 72c0141f03
3 changed files with 9 additions and 9 deletions

View 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

View File

@ -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.

View File

@ -132,16 +132,12 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
Py_DECREF(pto);
return NULL;
}
if (kw != NULL) {
pto->kw = PyDict_Copy(kw);
pto->kw = (kw != NULL) ? PyDict_Copy(kw) : PyDict_New();
if (pto->kw == NULL) {
Py_DECREF(pto);
return NULL;
}
} else {
pto->kw = Py_None;
Py_INCREF(Py_None);
}
pto->weakreflist = NULL;
pto->dict = NULL;