diff -r 4fc8951488b1 Lib/doctest.py --- a/Lib/doctest.py Sat May 24 11:43:29 2008 +0200 +++ b/Lib/doctest.py Sat May 24 12:51:00 2008 +0200 @@ -1226,11 +1226,11 @@ exec(compile(example.source, filename, "single", compileflags, 1), test.globs) self.debugger.set_continue() # ==== Example Finished ==== - exception = None + exc_info = None except KeyboardInterrupt: raise except: - exception = sys.exc_info() + exc_info = sys.exc_info() self.debugger.set_continue() # ==== Example Finished ==== got = self._fakeout.getvalue() # the actual output @@ -1239,13 +1239,12 @@ # If the example executed without raising any exceptions, # verify its output. - if exception is None: + if exc_info is None: if check(example.want, got, self.optionflags): outcome = SUCCESS # The example raised an exception: check if it was expected. else: - exc_info = sys.exc_info() exc_msg = traceback.format_exception_only(*exc_info[:2])[-1] if not quiet: got += _exception_traceback(exc_info) diff -r 4fc8951488b1 Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Sat May 24 11:43:29 2008 +0200 +++ b/Lib/test/test_exceptions.py Sat May 24 12:51:01 2008 +0200 @@ -427,6 +427,7 @@ local_ref = obj raise MyException(obj) + # Qualified "except" with "as" obj = MyObj() wr = weakref.ref(obj) try: @@ -437,6 +438,28 @@ obj = wr() self.failUnless(obj is None, "%s" % obj) + # Qualified "except" without "as" + obj = MyObj() + wr = weakref.ref(obj) + try: + inner_raising_func() + except MyException: + pass + obj = None + obj = wr() + self.failUnless(obj is None, "%s" % obj) + + # Bare "except" + obj = MyObj() + wr = weakref.ref(obj) + try: + inner_raising_func() + except: + pass + obj = None + obj = wr() + self.failUnless(obj is None, "%s" % obj) + def test_main(): run_unittest(ExceptionTests) diff -r 4fc8951488b1 Python/compile.c --- a/Python/compile.c Sat May 24 11:43:29 2008 +0200 +++ b/Python/compile.c Sat May 24 12:51:01 2008 +0200 @@ -2053,6 +2053,9 @@ ADDOP(c, POP_TOP); ADDOP(c, POP_TOP); VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body); + /* Clean up the exception state */ + ADDOP_O(c, LOAD_CONST, Py_None, consts); + ADDOP(c, END_FINALLY); } ADDOP_JREL(c, JUMP_FORWARD, end); compiler_use_next_block(c, except); diff -r 4fc8951488b1 Python/import.c --- a/Python/import.c Sat May 24 11:43:29 2008 +0200 +++ b/Python/import.c Sat May 24 12:51:01 2008 +0200 @@ -86,8 +86,9 @@ 3100 (merge from 2.6a0, see 62151) 3102 (__file__ points to source file) Python 3.0a4: 3110 (WITH_CLEANUP optimization). + Python 3.0a5: 3120 (correct exception cleanup) */ -#define MAGIC (3110 | ((long)'\r'<<16) | ((long)'\n'<<24)) +#define MAGIC (3120 | ((long)'\r'<<16) | ((long)'\n'<<24)) /* Magic word as global; note that _PyImport_Init() can change the value of this global to accommodate for alterations of how the