Mercurial > cpython-lru_cache-weakref
diff Objects/setobject.c @ 30995:d4826e097a3f legacy-trunk
Allow temporary hashability for the __contains__ test.
(Requested by Alex Martelli.)
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Nov 2003 18:36:54 +0000 |
| parents | 632b223cb8e8 |
| children | 622a76bc0237 |
line wrap: on
line diff
--- a/Objects/setobject.c Fri Nov 21 07:56:36 2003 +0000 +++ b/Objects/setobject.c Fri Nov 21 18:36:54 2003 +0000 @@ -104,7 +104,23 @@ 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 *
