]> granicus.if.org Git - python/commitdiff
Patch #1537 from Chad Austin
authorChristian Heimes <christian@cheimes.de>
Mon, 3 Dec 2007 20:01:02 +0000 (20:01 +0000)
committerChristian Heimes <christian@cheimes.de>
Mon, 3 Dec 2007 20:01:02 +0000 (20:01 +0000)
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)

Doc/library/exceptions.rst
Doc/reference/expressions.rst
Lib/test/exception_hierarchy.txt
Lib/test/test_generators.py
Misc/NEWS
Objects/exceptions.c

index 9fa5022d9012a2ad81edcd06245a39de3b6b5ecc..7b1f1b9a72d4ed44d21bdb1202fcd0fd88ca9c8e 100644 (file)
@@ -153,11 +153,13 @@ The following exceptions are the exceptions that are actually raised.
 .. exception:: GeneratorExit
 
    Raise when a :term:`generator`\'s :meth:`close` method is called.  It
-   directly inherits from :exc:`Exception` instead of :exc:`StandardError` since
+   directly inherits from :exc:`BaseException` instead of :exc:`StandardError` since
    it is technically not an error.
 
    .. versionadded:: 2.5
 
+   .. versionchanged:: 2.6
+      Changed to inherit from :exc:`BaseException`.
 
 .. exception:: IOError
 
index 706d0f1951686e7847269b7261d4bade3cc252b0..0f45f94ce34220145786138f7dd6211c673ebe28 100644 (file)
@@ -430,9 +430,6 @@ generator functions::
    ...         while True:
    ...             try:
    ...                 value = (yield value)
-   ...             except GeneratorExit:
-   ...                 # never catch GeneratorExit
-   ...                 raise
    ...             except Exception, e:
    ...                 value = e
    ...     finally:
index a03f7bbd71876130ad6642844813e235614baeb0..1be5ce09be8b12bd896a0ea92b8bb9c10b9716a8 100644 (file)
@@ -1,8 +1,8 @@
 BaseException
  +-- SystemExit
  +-- KeyboardInterrupt
+ +-- GeneratorExit
  +-- Exception
-      +-- GeneratorExit
       +-- StopIteration
       +-- StandardError
       |    +-- ArithmeticError
@@ -33,10 +33,10 @@ BaseException
       |    +-- SystemError
       |    +-- TypeError
       |    +-- ValueError
-      |    |    +-- UnicodeError
-      |    |         +-- UnicodeDecodeError
-      |    |         +-- UnicodeEncodeError
-      |    |         +-- UnicodeTranslateError
+      |         +-- UnicodeError
+      |              +-- UnicodeDecodeError
+      |              +-- UnicodeEncodeError
+      |              +-- UnicodeTranslateError
       +-- Warning
            +-- DeprecationWarning
            +-- PendingDeprecationWarning
index 5d50187b2c6a23f4efe0c1f7714ff7bd3ceeb669..ce3db72e66c489eaf9f08a8f7b0c2e49d76dccd8 100644 (file)
@@ -1658,6 +1658,19 @@ And finalization:
 exiting
 
 
+GeneratorExit is not caught by except Exception:
+
+>>> def f():
+...     try: yield
+...     except Exception: print 'except'
+...     finally: print 'finally'
+
+>>> g = f()
+>>> g.next()
+>>> del g
+finally
+
+
 Now let's try some ill-behaved generators:
 
 >>> def f():
index a1d1160fe55ede2836550817859d4a43ed014971..4c3369c7e633e3e5f35603f0bc3050635c5aaccc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -305,6 +305,8 @@ Core and builtins
 
 - Bug #1664966: Fix crash in exec if Unicode filename can't be decoded.
 
+- Issue #1537: Changed GeneratorExit's base class from Exception to BaseException.
+
 Library
 -------
 
index 64f655ceb07929b619bbb60707301015ce654de8..f7c44e7e5c96e6f041a13a16d909eea45e525ff3 100644 (file)
@@ -437,9 +437,9 @@ SimpleExtendsException(PyExc_Exception, StopIteration,
 
 
 /*
- *    GeneratorExit extends Exception
+ *    GeneratorExit extends BaseException
  */
-SimpleExtendsException(PyExc_Exception, GeneratorExit,
+SimpleExtendsException(PyExc_BaseException, GeneratorExit,
                        "Request that a generator exit.");