Commit a1e34222 authored by Martin v. Löwis's avatar Martin v. Löwis

Correctly forward exception in instance_contains().

Fixes #1591996. Patch contributed by Neal Norwitz.
parent cf1e760d
...@@ -172,6 +172,14 @@ testme ^ 1 ...@@ -172,6 +172,14 @@ testme ^ 1
# List/dict operations # List/dict operations
class Empty: pass
try:
1 in Empty()
print 'failed, should have raised TypeError'
except TypeError:
pass
1 in testme 1 in testme
testme[1] testme[1]
......
...@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? ...@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
Core and builtins Core and builtins
----------------- -----------------
- Bug #1591996: Correctly forward exception in instance_contains().
- Bug #1588287: fix invalid assertion for `1,2` in debug builds. - Bug #1588287: fix invalid assertion for `1,2` in debug builds.
- Bug #1576657: when setting a KeyError for a tuple key, make sure that - Bug #1576657: when setting a KeyError for a tuple key, make sure that
......
...@@ -1318,15 +1318,17 @@ instance_contains(PyInstanceObject *inst, PyObject *member) ...@@ -1318,15 +1318,17 @@ instance_contains(PyInstanceObject *inst, PyObject *member)
/* Couldn't find __contains__. */ /* Couldn't find __contains__. */
if (PyErr_ExceptionMatches(PyExc_AttributeError)) { if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_ssize_t rc;
/* Assume the failure was simply due to that there is no /* Assume the failure was simply due to that there is no
* __contains__ attribute, and try iterating instead. * __contains__ attribute, and try iterating instead.
*/ */
PyErr_Clear(); PyErr_Clear();
return _PySequence_IterSearch((PyObject *)inst, member, rc = _PySequence_IterSearch((PyObject *)inst, member,
PY_ITERSEARCH_CONTAINS) > 0; PY_ITERSEARCH_CONTAINS);
if (rc >= 0)
return rc > 0;
} }
else return -1;
return -1;
} }
static PySequenceMethods static PySequenceMethods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment