diff options
author | Eric V. Smith <eric@trueblade.com> | 2016-09-03 13:18:34 (GMT) |
---|---|---|
committer | Eric V. Smith <eric@trueblade.com> | 2016-09-03 13:18:34 (GMT) |
commit | 6a4efce7a50f1339dd67f892cc8746f5c1047ada (patch) | |
tree | df1a4793f118436be8c701762579f7c716d1d2af /Python/ast.c | |
parent | 3b09cd64e0a7991bcb6d3f83a0a23be2fc81213f (diff) | |
download | cpython-6a4efce7a50f1339dd67f892cc8746f5c1047ada.zip cpython-6a4efce7a50f1339dd67f892cc8746f5c1047ada.tar.gz cpython-6a4efce7a50f1339dd67f892cc8746f5c1047ada.tar.bz2 |
Closes issue 27921: Disallow backslashes anywhere in f-strings. This is a temporary restriction. In 3.6 beta 2, the plan is to again allow backslashes in the string parts of f-strings, but disallow them in the expression parts.
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Python/ast.c b/Python/ast.c index b56fadd..0f9c193 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4958,6 +4958,16 @@ parsestr(struct compiling *c, const node *n, int *bytesmode, int *fmode) return NULL; } } + + /* Temporary hack: if this is an f-string, no backslashes are allowed. */ + /* See issue 27921. */ + if (*fmode && strchr(s, '\\') != NULL) { + /* Syntax error. At a later date fix this so it only checks for + backslashes within the braces. */ + ast_error(c, n, "backslashes not allowed in f-strings"); + return NULL; + } + /* Avoid invoking escape decoding routines if possible. */ rawmode = rawmode || strchr(s, '\\') == NULL; if (*bytesmode) { |