summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-26 00:32:18 (GMT)
committerGitHub <noreply@github.com>2020-05-26 00:32:18 (GMT)
commitf7b1e461567e5e3fa3ba46f589d9edc1b45b2dd0 (patch)
treeae35c88616222dd863201ea8549ac09c30d9b407 /Parser
parent2602d97a0ae92b2d320909024e901c202b003e14 (diff)
downloadcpython-f7b1e461567e5e3fa3ba46f589d9edc1b45b2dd0.zip
cpython-f7b1e461567e5e3fa3ba46f589d9edc1b45b2dd0.tar.gz
cpython-f7b1e461567e5e3fa3ba46f589d9edc1b45b2dd0.tar.bz2
bpo-38964: Print correct filename on a SyntaxError in an fstring (GH-20399)
When a `SyntaxError` in the expression part of a fstring is found, the filename attribute of the `SyntaxError` is always `<fstring>`. With this commit, it gets changed to always have the name of the file the fstring resides in. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/pegen/parse_string.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/Parser/pegen/parse_string.c b/Parser/pegen/parse_string.c
index ca4b733..a0ec698 100644
--- a/Parser/pegen/parse_string.c
+++ b/Parser/pegen/parse_string.c
@@ -606,11 +606,8 @@ fstring_compile_expr(Parser *p, const char *expr_start, const char *expr_end,
if (tok == NULL) {
return NULL;
}
- tok->filename = PyUnicode_FromString("<fstring>");
- if (!tok->filename) {
- PyTokenizer_Free(tok);
- return NULL;
- }
+ Py_INCREF(p->tok->filename);
+ tok->filename = p->tok->filename;
Parser *p2 = _PyPegen_Parser_New(tok, Py_fstring_input, p->flags, p->feature_version,
NULL, p->arena);