]> granicus.if.org Git - python/commitdiff
Support throw() of string exceptions.
authorPhillip J. Eby <pje@telecommunity.com>
Sat, 25 Mar 2006 00:05:50 +0000 (00:05 +0000)
committerPhillip J. Eby <pje@telecommunity.com>
Sat, 25 Mar 2006 00:05:50 +0000 (00:05 +0000)
Lib/test/test_generators.py
Objects/genobject.c

index 4be1b4c5252d6559a6cabaa1d01036cce3d0e4e0..6b9b491350895b56a2d313f3ba8d271f5bb1855b 100644 (file)
@@ -1545,6 +1545,9 @@ caught ValueError (1)
 >>> 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 @@ ValueError: 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:
 
index 3f6ef859eedbbe2704bdbf0cbbfd5b1b07be826c..e7b8f8754a1f93af1564b6a7dabb75031405a04d 100644 (file)
@@ -249,7 +249,10 @@ gen_throw(PyGenObject *gen, PyObject *args)
                        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",