summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-11-21 18:36:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-11-21 18:36:54 (GMT)
commit19c2d77842290af9b5f470c1eea2a71d1f77c9fe (patch)
treeb803a0c96878f6bbef74c8f306df3e950f63da62 /Objects
parent3fbec701cae361de6beca55bc926e0540635f165 (diff)
downloadcpython-19c2d77842290af9b5f470c1eea2a71d1f77c9fe.zip
cpython-19c2d77842290af9b5f470c1eea2a71d1f77c9fe.tar.gz
cpython-19c2d77842290af9b5f470c1eea2a71d1f77c9fe.tar.bz2
Allow temporary hashability for the __contains__ test.
(Requested by Alex Martelli.)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 88d5640..2d77c74 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -104,7 +104,23 @@ set_len(PySetObject *so)
static int
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 *