Commit 44eeaec1 authored by Christian Heimes's avatar Christian Heimes

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.)
parent cbcfe4f3
...@@ -153,11 +153,13 @@ The following exceptions are the exceptions that are actually raised. ...@@ -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
......
...@@ -430,9 +430,6 @@ generator functions:: ...@@ -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:
......
BaseException BaseException
+-- SystemExit +-- SystemExit
+-- KeyboardInterrupt +-- KeyboardInterrupt
+-- Exception
+-- GeneratorExit +-- GeneratorExit
+-- Exception
+-- StopIteration +-- StopIteration
+-- StandardError +-- StandardError
| +-- ArithmeticError | +-- ArithmeticError
...@@ -33,10 +33,10 @@ BaseException ...@@ -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
......
...@@ -1658,6 +1658,19 @@ And finalization: ...@@ -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():
......
...@@ -305,6 +305,8 @@ Core and builtins ...@@ -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
------- -------
......
...@@ -437,9 +437,9 @@ SimpleExtendsException(PyExc_Exception, StopIteration, ...@@ -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.");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment