diff -r 9d0f4da4d531 Lib/test/test_dictviews.py --- a/Lib/test/test_dictviews.py Sat Sep 17 01:30:48 2016 +0300 +++ b/Lib/test/test_dictviews.py Sat Sep 17 23:14:03 2016 +0800 @@ -220,6 +220,30 @@ self.assertRaises((TypeError, pickle.PicklingError), pickle.dumps, d.items(), proto) + def test_compare_error(self): + class Exc(Exception): pass + class BadEq: + def __hash__(self): + return 7 + def __eq__(self, other): + raise Exc + + k1, k2 = BadEq(), BadEq() + v1, v2 = BadEq(), BadEq() + d = {k1: v1} + + self.assertIn(k1, d) + self.assertIn(k1, d.keys()) + self.assertIn(v1, d.values()) + self.assertIn((k1, v1), d.items()) + + self.assertRaises(Exc, d.__contains__, k2) + self.assertRaises(Exc, d.keys().__contains__, k2) + self.assertRaises(Exc, d.items().__contains__, (k2, v1)) + self.assertRaises(Exc, d.items().__contains__, (k1, v2)) + with self.assertRaises(Exc): + v2 in d.values() + def test_abc_registry(self): d = dict(a=1) diff -r 9d0f4da4d531 Objects/dictobject.c --- a/Objects/dictobject.c Sat Sep 17 01:30:48 2016 +0300 +++ b/Objects/dictobject.c Sat Sep 17 23:14:03 2016 +0800 @@ -4035,7 +4035,7 @@ return 0; key = PyTuple_GET_ITEM(obj, 0); value = PyTuple_GET_ITEM(obj, 1); - found = PyDict_GetItem((PyObject *)dv->dv_dict, key); + found = PyDict_GetItemWithError((PyObject *)dv->dv_dict, key); if (found == NULL) { if (PyErr_Occurred()) return -1;