mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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:
parent
3b09cd64e0
commit
6a4efce7a5
6 changed files with 69 additions and 98 deletions
10
Python/ast.c
10
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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue