[Python-checkins] r52662 - in python/trunk: Lib/test/test_class.py Objects/classobject.c
martin.v.loewis
python-checkins at python.org
Wed Nov 8 07:46:38 CET 2006
Author: martin.v.loewis
Date: Wed Nov 8 07:46:37 2006
New Revision: 52662
Modified:
python/trunk/Lib/test/test_class.py
python/trunk/Objects/classobject.c
Log:
Correctly forward exception in instance_contains().
Fixes #1591996. Patch contributed by Neal Norwitz.
Will backport.
Modified: python/trunk/Lib/test/test_class.py
==============================================================================
--- python/trunk/Lib/test/test_class.py (original)
+++ python/trunk/Lib/test/test_class.py Wed Nov 8 07:46:37 2006
@@ -172,6 +172,14 @@
# List/dict operations
+class Empty: pass
+
+try:
+ 1 in Empty()
+ print 'failed, should have raised TypeError'
+except TypeError:
+ pass
+
1 in testme
testme[1]
Modified: python/trunk/Objects/classobject.c
==============================================================================
--- python/trunk/Objects/classobject.c (original)
+++ python/trunk/Objects/classobject.c Wed Nov 8 07:46:37 2006
@@ -1318,15 +1318,17 @@
/* 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
More information about the Python-checkins
mailing list