diff -r 7f605fa1688d Lib/test/test_compile.py --- a/Lib/test/test_compile.py Tue Mar 08 21:33:21 2011 +0100 +++ b/Lib/test/test_compile.py Tue Mar 08 23:21:51 2011 +0100 @@ -38,6 +38,14 @@ def test_syntax_error(self): self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec") + # issue11441: test if a syntax error in an + # except clause raises the correct exception + with self.assertRaises(SyntaxError): + try: + raise Exception() + except Exception: + compile('1 = 1', '', 'exec') + def test_none_keyword_arg(self): self.assertRaises(SyntaxError, compile, "f(None=1)", "", "exec") diff -r 7f605fa1688d Python/ast.c --- a/Python/ast.c Tue Mar 08 21:33:21 2011 +0100 +++ b/Python/ast.c Tue Mar 08 23:21:51 2011 +0100 @@ -109,6 +109,15 @@ return; PyErr_Fetch(&type, &value, &tback); + if (PyExceptionInstance_Check(value)) { + /* value is not a tuple but an exception instance */ + tmp = ((PyBaseExceptionObject *) value)->args; + Py_INCREF(tmp); + Py_DECREF(value); + value = tmp; + } + assert(PyTuple_Check(value)); + errstr = PyTuple_GetItem(value, 0); if (!errstr) return; @@ -150,6 +159,7 @@ Py_DECREF(tmp); if (!value) return; + PyErr_NormalizeException(&type, &value, &tback); PyErr_Restore(type, value, tback); }