[Python-ideas] Let’s make escaping in f-literals impossible

Steve Dower steve.dower at python.org
Fri Aug 19 15:45:42 EDT 2016


On 19Aug2016 1157, Guido van Rossum wrote:
> I don't think we should take action now.
>
> Would it make sense, as a precaution, to declare the PEP provisional for
> one release? Then we can develop a sense of whether the current approach
> causes real problems.
>
> We could also emit some kind of warning if the expression part contains
> an escaped quote, since that's where a potential change would cause
> breakage. (Or we could leave that to the linters.)

After reading the responses, I like the idea of explicitly discouraging 
any sort of string escapes within the expression (whether quotes or 
special characters), but think it's best left for the linters and style 
guides.

Basically, avoid writing a literal f'{expr}' where you'd need to modify 
expr at all to rewrite it as:

 >>> x = expr
 >>> f'{x}'


We will almost certainly be looking to enable code completions and 
syntax highlighting in Visual Studio within expressions, and we can't 
easily process the string and then parse it for this purpose, but I 
think we'll be able to gracefully degrade in cases where escapes that 
are valid in strings are not valid in code.

Cheers,
Steve


More information about the Python-ideas mailing list