mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Allow temporary hashability for the __contains__ test.
(Requested by Alex Martelli.)
This commit is contained in:
parent
3fbec701ca
commit
19c2d77842
2 changed files with 19 additions and 1 deletions
|
@ -35,6 +35,8 @@ class TestJointOps(unittest.TestCase):
|
||||||
for c in self.letters:
|
for c in self.letters:
|
||||||
self.assertEqual(c in self.s, c in self.d)
|
self.assertEqual(c in self.s, c in self.d)
|
||||||
self.assertRaises(TypeError, self.s.__contains__, [[]])
|
self.assertRaises(TypeError, self.s.__contains__, [[]])
|
||||||
|
s = self.thetype([frozenset(self.letters)])
|
||||||
|
self.assert_(self.thetype(self.letters) in s)
|
||||||
|
|
||||||
def test_copy(self):
|
def test_copy(self):
|
||||||
dup = self.s.copy()
|
dup = self.s.copy()
|
||||||
|
|
|
@ -104,7 +104,23 @@ set_len(PySetObject *so)
|
||||||
static int
|
static int
|
||||||
set_contains(PySetObject *so, PyObject *key)
|
set_contains(PySetObject *so, PyObject *key)
|
||||||
{
|
{
|
||||||
return PySequence_Contains(so->data, key);
|
PyObject *olddict;
|
||||||
|
PySetObject *tmp;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
result = PySequence_Contains(so->data, key);
|
||||||
|
if (result == -1 && PyType_IsSubtype(key->ob_type, &PySet_Type)) {
|
||||||
|
PyErr_Clear();
|
||||||
|
tmp = (PySetObject *)make_new_set(&PyFrozenSet_Type, NULL);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return -1;
|
||||||
|
olddict = tmp->data;
|
||||||
|
tmp->data = ((PySetObject *)(key))->data;
|
||||||
|
result = PySequence_Contains(so->data, (PyObject *)tmp);
|
||||||
|
tmp->data = olddict;
|
||||||
|
Py_DECREF(tmp);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue