diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-11-08 06:46:49 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-11-08 06:46:49 +0000 |
commit | a1e3422205333a15c8f90c09c0883cf5e5139145 (patch) | |
tree | ae9d3236f0482c6a1dd4000ff89459bd79155600 | |
parent | cf1e760d3e91977f64336890d3dd0aa898b7fa25 (diff) | |
download | cpython-git-a1e3422205333a15c8f90c09c0883cf5e5139145.tar.gz |
Correctly forward exception in instance_contains().
Fixes #1591996. Patch contributed by Neal Norwitz.
-rw-r--r-- | Lib/test/test_class.py | 8 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-rw-r--r-- | Objects/classobject.c | 10 |
3 files changed, 16 insertions, 4 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 6c91deb129..26b8e7a134 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -172,6 +172,14 @@ testme ^ 1 # List/dict operations +class Empty: pass + +try: + 1 in Empty() + print 'failed, should have raised TypeError' +except TypeError: + pass + 1 in testme testme[1] @@ -12,6 +12,8 @@ What's New in Python 2.5.1c1? Core and builtins ----------------- +- Bug #1591996: Correctly forward exception in instance_contains(). + - Bug #1588287: fix invalid assertion for `1,2` in debug builds. - Bug #1576657: when setting a KeyError for a tuple key, make sure that diff --git a/Objects/classobject.c b/Objects/classobject.c index 7680a3d6d0..8560b6842c 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1318,15 +1318,17 @@ instance_contains(PyInstanceObject *inst, PyObject *member) /* Couldn't find __contains__. */ if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + Py_ssize_t rc; /* Assume the failure was simply due to that there is no * __contains__ attribute, and try iterating instead. */ PyErr_Clear(); - return _PySequence_IterSearch((PyObject *)inst, member, - PY_ITERSEARCH_CONTAINS) > 0; + rc = _PySequence_IterSearch((PyObject *)inst, member, + PY_ITERSEARCH_CONTAINS); + if (rc >= 0) + return rc > 0; } - else - return -1; + return -1; } static PySequenceMethods |