summaryrefslogtreecommitdiff
path: root/Parser
diff options
context:
space:
mode:
authorLysandros Nikolaou <lisandrosnik@gmail.com>2020-05-26 04:24:31 +0300
committerGitHub <noreply@github.com>2020-05-26 02:24:31 +0100
commit791a46ed58f74d673cf2c0d81deec57155bf7583 (patch)
tree26b3037aba7bcaafdb3a3f83ec73ebdc835511df /Parser
parent6cb0ad20396116b5076a58b05b55286d6d5e0c94 (diff)
downloadcpython-git-791a46ed58f74d673cf2c0d81deec57155bf7583.tar.gz
[3.9] bpo-38964: Print correct filename on a SyntaxError in an fstring (GH-20399) (GH-20404)
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>. (cherry picked from commit f7b1e461567e5e3fa3ba46f589d9edc1b45b2dd0)
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 ca4b733c15..a0ec698fa5 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);