
On 18Aug2016 1215, Terry Reedy wrote:
On 8/18/2016 12:50 PM, Steve Dower wrote:
I don't think f'{x.partition('-')[0]}' is any less readable as a result of the reused quotes,
I find it hard to not read f'{x.partition(' + ')[0]}' as string concatenation.
That's a fair counter-example. Though f'{x.partition(\' + \')[0]}' still reads like string concatenation to me at first glance. YMMV.
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.
Won't it be broken anyway because of the new prefix? I'm sure there's a fairly straightforward way for a regex to say that a closing quote must not be preceded immediately by a backslash or by an open brace at all without a closing brace in between. Not having escapes within the expression makes it harder for everyone except the Python developer, in my opinion, and the rest of us ought to go out of our way for them. Cheers, Steve