g_partial = functools.partial(func, trigger, None, None, None, None, arg=None)
self.assertEqual(repr(g_partial),"functools.partial(Function(old_function), EvilObject, None, None, None, None, arg=None)")
+ def test_str_subclass_error(self):
+ class BadStr(str):
+ def __eq__(self, other):
+ raise RuntimeError
+ def __hash__(self):
+ return str.__hash__(self)
+
+ def f(**kwargs):
+ return kwargs
+ p = functools.partial(f, poison="")
+ with self.assertRaises(RuntimeError):
+ result = p(**{BadStr("poison"): "new_value"})
@unittest.skipUnless(c_functools, 'requires the C _functools module')
class TestPartialC(TestPartial, unittest.TestCase):
for (Py_ssize_t i = 0; i < nkwds; ++i) {
key = PyTuple_GET_ITEM(kwnames, i);
val = args[nargs + i];
- if (PyDict_Contains(pto->kw, key)) {
+ int contains = PyDict_Contains(pto->kw, key);
+ if (contains < 0) {
+ goto error;
+ }
+ else if (contains == 1) {
if (pto_kw_merged == NULL) {
pto_kw_merged = PyDict_Copy(pto->kw);
if (pto_kw_merged == NULL) {