]> granicus.if.org Git - python/commitdiff
Generators had their throw() method allowing string exceptions. That's a
authorBrett Cannon <bcannon@gmail.com>
Tue, 11 Sep 2007 21:02:28 +0000 (21:02 +0000)
committerBrett Cannon <bcannon@gmail.com>
Tue, 11 Sep 2007 21:02:28 +0000 (21:02 +0000)
no-no.

Fixes issue #1147.  Need to fix 2.5 to raise a proper warning if a string
exception is passed in.

Lib/test/test_generators.py
Misc/NEWS
Objects/genobject.c

index 2b0d47d1b63cdaf114ce02af0e9bc71ed44ebec3..5d50187b2c6a23f4efe0c1f7714ff7bd3ceeb669 100644 (file)
@@ -1622,7 +1622,7 @@ ValueError: 7
 >>> f().throw("abc")     # throw on just-opened generator
 Traceback (most recent call last):
   ...
-abc
+TypeError: exceptions must be classes, or instances, not str
 
 Now let's try closing a generator:
 
index 10f2c71e7ccf8eb180652a7d31901d478c45d589..e5e365a3d94f11e41d8f4b17fee6419ac645b99c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Issue #1147: Exceptions were directly allowing string exceptions in their
+  throw() method even though string exceptions no longer allowed.
+
 - Issue #1096: Prevent a segfault from getting the repr of a very deeply nested
   list by using the recursion counter.
 
index 14cc46b846b5442f6925de68c2e53b9764b5fe2c..551d9fddc23d9e1036b6a223762652a86f466313 100644 (file)
@@ -252,10 +252,7 @@ gen_throw(PyGenObject *gen, PyObject *args)
                        Py_INCREF(typ);
                }
        }
-
-       /* Allow raising builtin string exceptions */
-
-       else if (!PyString_CheckExact(typ)) {
+       else {
                /* Not something you can raise.  throw() fails. */
                PyErr_Format(PyExc_TypeError,
                             "exceptions must be classes, or instances, not %s",