Index: Objects/exceptions.c =================================================================== --- Objects/exceptions.c (revision 59280) +++ Objects/exceptions.c (working copy) @@ -437,9 +437,9 @@ /* - * GeneratorExit extends Exception + * GeneratorExit extends BaseException */ -SimpleExtendsException(PyExc_Exception, GeneratorExit, +SimpleExtendsException(PyExc_BaseException, GeneratorExit, "Request that a generator exit."); Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 59280) +++ Misc/NEWS (working copy) @@ -301,6 +301,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 ------- Index: Doc/reference/expressions.rst =================================================================== --- Doc/reference/expressions.rst (revision 59280) +++ Doc/reference/expressions.rst (working copy) @@ -430,9 +430,6 @@ ... while True: ... try: ... value = (yield value) - ... except GeneratorExit: - ... # never catch GeneratorExit - ... raise ... except Exception, e: ... value = e ... finally: Index: Doc/library/exceptions.rst =================================================================== --- Doc/library/exceptions.rst (revision 59280) +++ Doc/library/exceptions.rst (working copy) @@ -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 Index: Lib/test/test_generators.py =================================================================== --- Lib/test/test_generators.py (revision 59280) +++ Lib/test/test_generators.py (working copy) @@ -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(): Index: Lib/test/exception_hierarchy.txt =================================================================== --- Lib/test/exception_hierarchy.txt (revision 59280) +++ Lib/test/exception_hierarchy.txt (working copy) @@ -1,8 +1,8 @@ BaseException +-- SystemExit +-- KeyboardInterrupt + +-- GeneratorExit +-- Exception - +-- GeneratorExit +-- StopIteration +-- StandardError | +-- ArithmeticError