File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -386,6 +386,12 @@ def test_parse(self):
386386 b = compile ('foo(1 + 1)' , '<unknown>' , 'exec' , ast .PyCF_ONLY_AST )
387387 self .assertEqual (ast .dump (a ), ast .dump (b ))
388388
389+ def test_parse_in_error (self ):
390+ try :
391+ 1 / 0
392+ except Exception :
393+ self .assertRaises (SyntaxError , ast .parse , r"'\U'" )
394+
389395 def test_dump (self ):
390396 node = ast .parse ('spam(eggs, "and cheese")' )
391397 self .assertEqual (ast .dump (node ),
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010Core and Builtins
1111-----------------
1212
13+ - Issue #15846: Fix SystemError which happened when using ast.parse in an
14+ exception handler on code with syntax errors.
15+
1316- Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X.
1417
1518- Issue #15801: Make sure mappings passed to '%' formatting are actually
Original file line number Diff line number Diff line change @@ -92,7 +92,15 @@ ast_error(const node *n, const char *errstr)
9292 PyObject * u = Py_BuildValue ("zii" , errstr , LINENO (n ), n -> n_col_offset );
9393 if (!u )
9494 return 0 ;
95+ /*
96+ * Prevent the error from being chained. PyErr_SetObject will normalize the
97+ * exception in order to chain it. ast_error_finish, however, requires the
98+ * error not to be normalized.
99+ */
100+ PyObject * save = PyThreadState_GET ()-> exc_value ;
101+ PyThreadState_GET ()-> exc_value = NULL ;
95102 PyErr_SetObject (PyExc_SyntaxError , u );
103+ PyThreadState_GET ()-> exc_value = save ;
96104 Py_DECREF (u );
97105 return 0 ;
98106}
You can’t perform that action at this time.
0 commit comments