From 6a4efce7a50f1339dd67f892cc8746f5c1047ada Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Sat, 3 Sep 2016 09:18:34 -0400 Subject: 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. --- Python/ast.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Python') diff --git a/Python/ast.c b/Python/ast.c index b56fadddda..0f9c19333d 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) { -- cgit v1.2.1