[Python-3000-checkins] r59296 - in python/branches/py3k: Doc/library/exceptions.rst Doc/reference/expressions.rst Lib/distutils/msvc9compiler.py Lib/test/exception_hierarchy.txt Lib/test/test_generators.py Misc/NEWS Objects/exceptions.c

christian.heimes python-3000-checkins at python.org
Mon Dec 3 20:47:55 CET 2007


Author: christian.heimes
Date: Mon Dec  3 20:47:54 2007
New Revision: 59296

Added:
   python/branches/py3k/Lib/distutils/msvc9compiler.py
      - copied unchanged from r59290, python/trunk/Lib/distutils/msvc9compiler.py
Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Doc/library/exceptions.rst
   python/branches/py3k/Doc/reference/expressions.rst
   python/branches/py3k/Lib/test/exception_hierarchy.txt
   python/branches/py3k/Lib/test/test_generators.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/exceptions.c
Log:
Patch #1537 from Chad Austin
Change GeneratorExit's base class from Exception to BaseException

Modified: python/branches/py3k/Doc/library/exceptions.rst
==============================================================================
--- python/branches/py3k/Doc/library/exceptions.rst	(original)
+++ python/branches/py3k/Doc/library/exceptions.rst	Mon Dec  3 20:47:54 2007
@@ -135,6 +135,13 @@
 
 .. exception:: GeneratorExit
 
+     Raise when a :term:`generator`\'s :meth:`close` method is called.  It
+     directly inherits from :exc:`BaseException` instead of :exc:`Exception` since
+     it is technically not an error.
+
+    .. versionchanged:: 3.0 
+       Changed to inherit from :exc:`BaseException`.
+
    Raise when a :term:`generator`\'s :meth:`close` method is called.
 
 

Modified: python/branches/py3k/Doc/reference/expressions.rst
==============================================================================
--- python/branches/py3k/Doc/reference/expressions.rst	(original)
+++ python/branches/py3k/Doc/reference/expressions.rst	Mon Dec  3 20:47:54 2007
@@ -413,9 +413,6 @@
    ...         while True:
    ...             try:
    ...                 value = (yield value)
-   ...             except GeneratorExit:
-   ...                 # never catch GeneratorExit
-   ...                 raise
    ...             except Exception, e:
    ...                 value = e
    ...     finally:

Modified: python/branches/py3k/Lib/test/exception_hierarchy.txt
==============================================================================
--- python/branches/py3k/Lib/test/exception_hierarchy.txt	(original)
+++ python/branches/py3k/Lib/test/exception_hierarchy.txt	Mon Dec  3 20:47:54 2007
@@ -1,8 +1,8 @@
 BaseException
  +-- SystemExit
  +-- KeyboardInterrupt
+ +-- GeneratorExit
  +-- Exception
-      +-- GeneratorExit
       +-- StopIteration
       +-- ArithmeticError
       |    +-- FloatingPointError

Modified: python/branches/py3k/Lib/test/test_generators.py
==============================================================================
--- python/branches/py3k/Lib/test/test_generators.py	(original)
+++ python/branches/py3k/Lib/test/test_generators.py	Mon Dec  3 20:47:54 2007
@@ -1668,6 +1668,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/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Mon Dec  3 20:47:54 2007
@@ -245,6 +245,8 @@
   * operator module: div, idiv, __div__, __idiv__, isCallable, sequenceIncludes
   * sys module: exc_clear(), exc_type, exc_value, exc_traceback
 
+- Issue #1537: Changed GeneratorExit's base class from Exception to BaseException.
+
 
 Library
 -------

Modified: python/branches/py3k/Objects/exceptions.c
==============================================================================
--- python/branches/py3k/Objects/exceptions.c	(original)
+++ python/branches/py3k/Objects/exceptions.c	Mon Dec  3 20:47:54 2007
@@ -424,9 +424,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-3000-checkins mailing list