
On 8/18/2016 3:15 PM, Terry Reedy wrote:
On 8/18/2016 12:50 PM, Steve Dower wrote: I find it hard to not read f'{x.partition(' + ')[0]}' as string concatenation.
and it will certainly be easier for highlighters to handle (assuming they're doing anything more complicated than simply displaying the entire expression in a different colour).
Without the escapes, existing f-unaware highlighters like IDLE's will be broken in that they will highlight the single f-string as two strings with differently highlighted content in the middle. For f'{x.partition('if')[0]}', the 'if' is and will be erroneously highlighted as a keyword. I consider this breakage unacceptible.
Right. Because all strings (regardless of prefixes) are first parsed as strings, and then have their prefix "operator" applied, it's easy for a parser to ignore any sting prefix character. So something that parses or scans a Python file and currently understands u, b, and r to be string prefixes, just needs to add f to the prefixes it uses, and it can now at least understand f-strings (and fr-strings). It doesn't need to implement a full-blown expression parser just to find out where the end of a f-string is. Eric.