summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-19 04:46:08 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-09-19 04:46:08 (GMT)
commit6692f01c91b9ca0eafc4e8033bb2757b70f83fa4 (patch)
tree620a6cbc512e7e23e52b2cdf46bbdbe9b318ad44
parent5820f3a3814f0e4983229424388a5e2964758b03 (diff)
downloadcpython-6692f01c91b9ca0eafc4e8033bb2757b70f83fa4.zip
cpython-6692f01c91b9ca0eafc4e8033bb2757b70f83fa4.tar.gz
cpython-6692f01c91b9ca0eafc4e8033bb2757b70f83fa4.tar.bz2
merge
-rw-r--r--Lib/test/test_dictviews.py26
-rw-r--r--Objects/dictobject.c2
2 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
index 4c290ff..49a9e9c 100644
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -210,6 +210,32 @@ class DictSetTest(unittest.TestCase):
self.assertRaises(TypeError, copy.copy, d.values())
self.assertRaises(TypeError, copy.copy, d.items())
+ 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_pickle(self):
d = {1: 10, "a": "ABC"}
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 0476442..25fdedd 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -4035,7 +4035,7 @@ dictitems_contains(_PyDictViewObject *dv, PyObject *obj)
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;