[Python-checkins] r52663 - in python/branches/release25-maint: Lib/test/test_class.py Misc/NEWS Objects/classobject.c

martin.v.loewis python-checkins at python.org
Wed Nov 8 07:46:49 CET 2006


Author: martin.v.loewis
Date: Wed Nov  8 07:46:49 2006
New Revision: 52663

Modified:
   python/branches/release25-maint/Lib/test/test_class.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Objects/classobject.c
Log:
Correctly forward exception in instance_contains().
Fixes #1591996. Patch contributed by Neal Norwitz.


Modified: python/branches/release25-maint/Lib/test/test_class.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_class.py	(original)
+++ python/branches/release25-maint/Lib/test/test_class.py	Wed Nov  8 07:46:49 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/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Wed Nov  8 07:46:49 2006
@@ -12,6 +12,8 @@
 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

Modified: python/branches/release25-maint/Objects/classobject.c
==============================================================================
--- python/branches/release25-maint/Objects/classobject.c	(original)
+++ python/branches/release25-maint/Objects/classobject.c	Wed Nov  8 07:46:49 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