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.

This commit is contained in:
Eric V. Smith 2016-09-03 09:18:34 -04:00
parent 3b09cd64e0
commit 6a4efce7a5
6 changed files with 69 additions and 98 deletions

View file

@ -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) {