Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e5fcc3

Browse files
committed
Fixed error creation if the problem is an empty expression in an f-string: use ast_error instead of PyErr_SetString.
1 parent 038b61f commit 1e5fcc3

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Python/ast.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,7 +4008,8 @@ decode_unicode(struct compiling *c, const char *s, size_t len, const char *encod
40084008
example. */
40094009
static expr_ty
40104010
fstring_compile_expr(PyObject *str, Py_ssize_t expr_start,
4011-
Py_ssize_t expr_end, PyArena *arena)
4011+
Py_ssize_t expr_end, struct compiling *c, const node *n)
4012+
40124013
{
40134014
PyCompilerFlags cf;
40144015
mod_ty mod;
@@ -4048,8 +4049,7 @@ fstring_compile_expr(PyObject *str, Py_ssize_t expr_start,
40484049
}
40494050
}
40504051
if (all_whitespace) {
4051-
PyErr_SetString(PyExc_SyntaxError, "f-string: empty expression "
4052-
"not allowed");
4052+
ast_error(c, n, "f-string: empty expression not allowed");
40534053
goto error;
40544054
}
40554055

@@ -4095,7 +4095,7 @@ fstring_compile_expr(PyObject *str, Py_ssize_t expr_start,
40954095

40964096
cf.cf_flags = PyCF_ONLY_AST;
40974097
mod = PyParser_ASTFromString(utf_expr, "<fstring>",
4098-
Py_eval_input, &cf, arena);
4098+
Py_eval_input, &cf, c->c_arena);
40994099
if (!mod)
41004100
goto error;
41014101

@@ -4370,8 +4370,7 @@ fstring_find_expr(PyObject *str, Py_ssize_t *ofs, int recurse_lvl,
43704370
/* Compile the expression as soon as possible, so we show errors
43714371
related to the expression before errors related to the
43724372
conversion or format_spec. */
4373-
simple_expression = fstring_compile_expr(str, expr_start, expr_end,
4374-
c->c_arena);
4373+
simple_expression = fstring_compile_expr(str, expr_start, expr_end, c, n);
43754374
if (!simple_expression)
43764375
return -1;
43774376

0 commit comments

Comments
 (0)