[Python-checkins] r43302 - in python/trunk: Lib/test/test_generators.py Objects/genobject.c

phillip.eby python-checkins at python.org
Sat Mar 25 01:05:53 CET 2006


Author: phillip.eby
Date: Sat Mar 25 01:05:50 2006
New Revision: 43302

Modified:
   python/trunk/Lib/test/test_generators.py
   python/trunk/Objects/genobject.c
Log:
Support throw() of string exceptions.


Modified: python/trunk/Lib/test/test_generators.py
==============================================================================
--- python/trunk/Lib/test/test_generators.py	(original)
+++ python/trunk/Lib/test/test_generators.py	Sat Mar 25 01:05:50 2006
@@ -1545,6 +1545,9 @@
 >>> g.throw(ValueError, TypeError(1))  # mismatched type, rewrapped
 caught ValueError (1)
 
+>>> g.throw(ValueError, ValueError(1), None)   # explicit None traceback
+caught ValueError (1)
+
 >>> g.throw(ValueError(1), "foo")       # bad args
 Traceback (most recent call last):
   ...
@@ -1592,8 +1595,7 @@
 >>> f().throw("abc")     # throw on just-opened generator
 Traceback (most recent call last):
   ...
-TypeError: exceptions must be classes, or instances, not str
-
+abc
 
 Now let's try closing a generator:
 

Modified: python/trunk/Objects/genobject.c
==============================================================================
--- python/trunk/Objects/genobject.c	(original)
+++ python/trunk/Objects/genobject.c	Sat Mar 25 01:05:50 2006
@@ -249,7 +249,10 @@
 			Py_INCREF(typ);
 		}
 	}
-	else {
+
+	/* Allow raising builtin string exceptions */
+
+	else if (!PyString_CheckExact(typ)) {
 		/* Not something you can raise.  throw() fails. */
 		PyErr_Format(PyExc_TypeError,
 			     "exceptions must be classes, or instances, not %s",


More information about the Python-checkins mailing list