[Python-checkins] r59300 - in python/trunk: Doc/library/exceptions.rst Doc/reference/expressions.rst Lib/test/exception_hierarchy.txt Lib/test/test_generators.py Misc/NEWS Objects/exceptions.c

christian.heimes python-checkins at python.org
Mon Dec 3 21:01:03 CET 2007


Author: christian.heimes
Date: Mon Dec  3 21:01:02 2007
New Revision: 59300

Modified:
   python/trunk/Doc/library/exceptions.rst
   python/trunk/Doc/reference/expressions.rst
   python/trunk/Lib/test/exception_hierarchy.txt
   python/trunk/Lib/test/test_generators.py
   python/trunk/Misc/NEWS
   python/trunk/Objects/exceptions.c
Log:
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException
(This time I'm applying the patch to the correct sandbox.)

Modified: python/trunk/Doc/library/exceptions.rst
==============================================================================
--- python/trunk/Doc/library/exceptions.rst	(original)
+++ python/trunk/Doc/library/exceptions.rst	Mon Dec  3 21:01:02 2007
@@ -153,11 +153,13 @@
 .. 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
 

Modified: python/trunk/Doc/reference/expressions.rst
==============================================================================
--- python/trunk/Doc/reference/expressions.rst	(original)
+++ python/trunk/Doc/reference/expressions.rst	Mon Dec  3 21:01:02 2007
@@ -430,9 +430,6 @@
    ...         while True:
    ...             try:
    ...                 value = (yield value)
-   ...             except GeneratorExit:
-   ...                 # never catch GeneratorExit
-   ...                 raise
    ...             except Exception, e:
    ...                 value = e
    ...     finally:

Modified: python/trunk/Lib/test/exception_hierarchy.txt
==============================================================================
--- python/trunk/Lib/test/exception_hierarchy.txt	(original)
+++ python/trunk/Lib/test/exception_hierarchy.txt	Mon Dec  3 21:01:02 2007
@@ -1,8 +1,8 @@
 BaseException
  +-- SystemExit
  +-- KeyboardInterrupt
+ +-- GeneratorExit
  +-- Exception
-      +-- GeneratorExit
       +-- StopIteration
       +-- StandardError
       |    +-- ArithmeticError
@@ -33,10 +33,10 @@
       |    +-- SystemError
       |    +-- TypeError
       |    +-- ValueError
-      |    |    +-- UnicodeError
-      |    |         +-- UnicodeDecodeError
-      |    |         +-- UnicodeEncodeError
-      |    |         +-- UnicodeTranslateError
+      |         +-- UnicodeError
+      |              +-- UnicodeDecodeError
+      |              +-- UnicodeEncodeError
+      |              +-- UnicodeTranslateError
       +-- Warning
            +-- DeprecationWarning
            +-- PendingDeprecationWarning

Modified: python/trunk/Lib/test/test_generators.py
==============================================================================
--- python/trunk/Lib/test/test_generators.py	(original)
+++ python/trunk/Lib/test/test_generators.py	Mon Dec  3 21:01:02 2007
@@ -1658,6 +1658,19 @@
 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():

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Mon Dec  3 21:01:02 2007
@@ -305,6 +305,8 @@
 
 - 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
 -------
 

Modified: python/trunk/Objects/exceptions.c
==============================================================================
--- python/trunk/Objects/exceptions.c	(original)
+++ python/trunk/Objects/exceptions.c	Mon Dec  3 21:01:02 2007
@@ -437,9 +437,9 @@
 
 
 /*
- *    GeneratorExit extends Exception
+ *    GeneratorExit extends BaseException
  */
-SimpleExtendsException(PyExc_Exception, GeneratorExit,
+SimpleExtendsException(PyExc_BaseException, GeneratorExit,
                        "Request that a generator exit.");
 
 


More information about the Python-checkins mailing list