Kaydet (Commit) 72c0141f authored tarafından Benjamin Peterson's avatar Benjamin Peterson

ensure .keywords is always a dict

üst 36691efe
...@@ -89,9 +89,11 @@ class TestPartial(unittest.TestCase): ...@@ -89,9 +89,11 @@ class TestPartial(unittest.TestCase):
# exercise special code paths for no keyword args in # exercise special code paths for no keyword args in
# either the partial object or the caller # either the partial object or the caller
p = self.thetype(capture) p = self.thetype(capture)
self.assertEqual(p.keywords, {})
self.assertEqual(p(), ((), {})) self.assertEqual(p(), ((), {}))
self.assertEqual(p(a=1), ((), {'a':1})) self.assertEqual(p(a=1), ((), {'a':1}))
p = self.thetype(capture, a=1) p = self.thetype(capture, a=1)
self.assertEqual(p.keywords, {'a':1})
self.assertEqual(p(), ((), {'a':1})) self.assertEqual(p(), ((), {'a':1}))
self.assertEqual(p(b=2), ((), {'a':1, 'b':2})) self.assertEqual(p(b=2), ((), {'a':1, 'b':2}))
# keyword args in the call override those in the partial object # keyword args in the call override those in the partial object
......
...@@ -27,6 +27,8 @@ Core and Builtins ...@@ -27,6 +27,8 @@ Core and Builtins
Library Library
------- -------
- The keywords attribute of functools.partial is now always a dictionary.
- Issue #24134: assertRaises() and assertRaisesRegexp() checks are not longer - Issue #24134: assertRaises() and assertRaisesRegexp() checks are not longer
successful if the callable is None. successful if the callable is None.
......
...@@ -132,17 +132,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw) ...@@ -132,17 +132,13 @@ partial_new(PyTypeObject *type, PyObject *args, PyObject *kw)
Py_DECREF(pto); Py_DECREF(pto);
return NULL; return NULL;
} }
if (kw != NULL) { pto->kw = (kw != NULL) ? PyDict_Copy(kw) : PyDict_New();
pto->kw = PyDict_Copy(kw); if (pto->kw == NULL) {
if (pto->kw == NULL) { Py_DECREF(pto);
Py_DECREF(pto); return NULL;
return NULL;
}
} else {
pto->kw = Py_None;
Py_INCREF(Py_None);
} }
pto->weakreflist = NULL; pto->weakreflist = NULL;
pto->dict = NULL; pto->dict = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment