mirror of
https://github.com/python/cpython.git
synced 2025-11-27 13:45:25 +00:00
merge
This commit is contained in:
parent
5820f3a381
commit
6692f01c91
2 changed files with 27 additions and 1 deletions
|
|
@ -210,6 +210,32 @@ class DictSetTest(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, copy.copy, d.values())
|
self.assertRaises(TypeError, copy.copy, d.values())
|
||||||
self.assertRaises(TypeError, copy.copy, d.items())
|
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):
|
def test_pickle(self):
|
||||||
d = {1: 10, "a": "ABC"}
|
d = {1: 10, "a": "ABC"}
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
|
|
|
||||||
|
|
@ -4035,7 +4035,7 @@ dictitems_contains(_PyDictViewObject *dv, PyObject *obj)
|
||||||
return 0;
|
return 0;
|
||||||
key = PyTuple_GET_ITEM(obj, 0);
|
key = PyTuple_GET_ITEM(obj, 0);
|
||||||
value = PyTuple_GET_ITEM(obj, 1);
|
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 (found == NULL) {
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue