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.)
This commit is contained in:
Christian Heimes 2007-12-03 20:01:02 +00:00
parent cbcfe4f3e4
commit 44eeaec173
6 changed files with 25 additions and 11 deletions

View File

@ -153,11 +153,13 @@ The following exceptions are the exceptions that are actually raised.
.. exception:: GeneratorExit .. exception:: GeneratorExit
Raise when a :term:`generator`\'s :meth:`close` method is called. It 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. it is technically not an error.
.. versionadded:: 2.5 .. versionadded:: 2.5
.. versionchanged:: 2.6
Changed to inherit from :exc:`BaseException`.
.. exception:: IOError .. exception:: IOError

View File

@ -430,9 +430,6 @@ generator functions::
... while True: ... while True:
... try: ... try:
... value = (yield value) ... value = (yield value)
... except GeneratorExit:
... # never catch GeneratorExit
... raise
... except Exception, e: ... except Exception, e:
... value = e ... value = e
... finally: ... finally:

View File

@ -1,8 +1,8 @@
BaseException BaseException
+-- SystemExit +-- SystemExit
+-- KeyboardInterrupt +-- KeyboardInterrupt
+-- Exception
+-- GeneratorExit +-- GeneratorExit
+-- Exception
+-- StopIteration +-- StopIteration
+-- StandardError +-- StandardError
| +-- ArithmeticError | +-- ArithmeticError
@ -33,10 +33,10 @@ BaseException
| +-- SystemError | +-- SystemError
| +-- TypeError | +-- TypeError
| +-- ValueError | +-- ValueError
| | +-- UnicodeError | +-- UnicodeError
| | +-- UnicodeDecodeError | +-- UnicodeDecodeError
| | +-- UnicodeEncodeError | +-- UnicodeEncodeError
| | +-- UnicodeTranslateError | +-- UnicodeTranslateError
+-- Warning +-- Warning
+-- DeprecationWarning +-- DeprecationWarning
+-- PendingDeprecationWarning +-- PendingDeprecationWarning

View File

@ -1658,6 +1658,19 @@ And finalization:
exiting 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: Now let's try some ill-behaved generators:
>>> def f(): >>> def f():

View File

@ -305,6 +305,8 @@ Core and builtins
- Bug #1664966: Fix crash in exec if Unicode filename can't be decoded. - 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 Library
------- -------

View 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."); "Request that a generator exit.");