diff options
author | Eric V. Smith <eric@trueblade.com> | 2015-09-24 12:52:04 (GMT) |
---|---|---|
committer | Eric V. Smith <eric@trueblade.com> | 2015-09-24 12:52:04 (GMT) |
commit | 1e5fcc3dea4263a5c01ecc4cd9b5d755fab5ee6a (patch) | |
tree | 6657bf59a9d3fc0501ad1db39fec7997efab5dfc /Python | |
parent | 038b61fbb54aceea62b44a45ee4ff4723a09ee7f (diff) | |
download | cpython-1e5fcc3dea4263a5c01ecc4cd9b5d755fab5ee6a.zip cpython-1e5fcc3dea4263a5c01ecc4cd9b5d755fab5ee6a.tar.gz cpython-1e5fcc3dea4263a5c01ecc4cd9b5d755fab5ee6a.tar.bz2 |
Fixed error creation if the problem is an empty expression in an f-string: use ast_error instead of PyErr_SetString.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Python/ast.c b/Python/ast.c index 83e4f00..7eab3c0 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4008,7 +4008,8 @@ decode_unicode(struct compiling *c, const char *s, size_t len, const char *encod example. */ static expr_ty fstring_compile_expr(PyObject *str, Py_ssize_t expr_start, - Py_ssize_t expr_end, PyArena *arena) + Py_ssize_t expr_end, struct compiling *c, const node *n) + { PyCompilerFlags cf; mod_ty mod; @@ -4048,8 +4049,7 @@ fstring_compile_expr(PyObject *str, Py_ssize_t expr_start, } } if (all_whitespace) { - PyErr_SetString(PyExc_SyntaxError, "f-string: empty expression " - "not allowed"); + ast_error(c, n, "f-string: empty expression not allowed"); goto error; } @@ -4095,7 +4095,7 @@ fstring_compile_expr(PyObject *str, Py_ssize_t expr_start, cf.cf_flags = PyCF_ONLY_AST; mod = PyParser_ASTFromString(utf_expr, "<fstring>", - Py_eval_input, &cf, arena); + Py_eval_input, &cf, c->c_arena); if (!mod) goto error; @@ -4370,8 +4370,7 @@ fstring_find_expr(PyObject *str, Py_ssize_t *ofs, int recurse_lvl, /* Compile the expression as soon as possible, so we show errors related to the expression before errors related to the conversion or format_spec. */ - simple_expression = fstring_compile_expr(str, expr_start, expr_end, - c->c_arena); + simple_expression = fstring_compile_expr(str, expr_start, expr_end, c, n); if (!simple_expression) return -1; |