mirror of
https://github.com/python/cpython.git
synced 2025-09-11 19:27:07 +00:00
merge 3.2 (#15846)
This commit is contained in:
commit
c7f447c89f
3 changed files with 17 additions and 0 deletions
|
@ -407,6 +407,12 @@ class ASTHelpers_Test(unittest.TestCase):
|
||||||
b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST)
|
b = compile('foo(1 + 1)', '<unknown>', 'exec', ast.PyCF_ONLY_AST)
|
||||||
self.assertEqual(ast.dump(a), ast.dump(b))
|
self.assertEqual(ast.dump(a), ast.dump(b))
|
||||||
|
|
||||||
|
def test_parse_in_error(self):
|
||||||
|
try:
|
||||||
|
1/0
|
||||||
|
except Exception:
|
||||||
|
self.assertRaises(SyntaxError, ast.parse, r"'\U'")
|
||||||
|
|
||||||
def test_dump(self):
|
def test_dump(self):
|
||||||
node = ast.parse('spam(eggs, "and cheese")')
|
node = ast.parse('spam(eggs, "and cheese")')
|
||||||
self.assertEqual(ast.dump(node),
|
self.assertEqual(ast.dump(node),
|
||||||
|
|
|
@ -12,6 +12,9 @@ Core and Builtins
|
||||||
|
|
||||||
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
|
- Issue #15839: Convert SystemErrors in super() to RuntimeErrors.
|
||||||
|
|
||||||
|
- Issue #15846: Fix SystemError which happened when using ast.parse in an
|
||||||
|
exception handler on code with syntax errors.
|
||||||
|
|
||||||
- Issue #15801: Make sure mappings passed to '%' formatting are actually
|
- Issue #15801: Make sure mappings passed to '%' formatting are actually
|
||||||
subscriptable.
|
subscriptable.
|
||||||
|
|
||||||
|
|
|
@ -588,7 +588,15 @@ ast_error(const node *n, const char *errstr)
|
||||||
PyObject *u = Py_BuildValue("zii", errstr, LINENO(n), n->n_col_offset);
|
PyObject *u = Py_BuildValue("zii", errstr, LINENO(n), n->n_col_offset);
|
||||||
if (!u)
|
if (!u)
|
||||||
return 0;
|
return 0;
|
||||||
|
/*
|
||||||
|
* Prevent the error from being chained. PyErr_SetObject will normalize the
|
||||||
|
* exception in order to chain it. ast_error_finish, however, requires the
|
||||||
|
* error not to be normalized.
|
||||||
|
*/
|
||||||
|
PyObject *save = PyThreadState_GET()->exc_value;
|
||||||
|
PyThreadState_GET()->exc_value = NULL;
|
||||||
PyErr_SetObject(PyExc_SyntaxError, u);
|
PyErr_SetObject(PyExc_SyntaxError, u);
|
||||||
|
PyThreadState_GET()->exc_value = save;
|
||||||
Py_DECREF(u);
|
Py_DECREF(u);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue