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

Serhiy Storchaka storchaka at gmail.com
Fri Aug 19 02:57:50 EDT 2016


On 19.08.16 08:07, Terry Reedy wrote:
> On 8/18/2016 3:30 PM, Steve Dower wrote:
>> 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,
>
> Why are you reusing the single quote', which needs the escaping that you
> don't like, instead of any of at least 6 alternatives that do not need
> any escaping?
>
> f'{x.partition("-")[0]}'
> f'{x.partition("""-""")[0]}'
> f"{x.partition('-')[0]}"
> f'''{x.partition('-')[0]}'''
> f"""{x.partition('-')[0]}"""
> f"""{x.partition('''-''')[0]}"""
>
> It seems to me that that this is at least somewhat a strawman issue.
>
> If you want to prohibit backslashed quote reuse in expressions, as in
> f'{x.partition(\'-\')[0]}', that is okay with me, as this is
> unnecessary* and arguably bad.  The third alternative above is better.
> What breaks colorizers, and what I therefore object to, is the
> innovation of adding magical escaping of ' or " without \.
>
> Or add a new style rule to PEP 8.

+1. It is even possible to add a SyntaxWarning in future.




More information about the Python-ideas mailing list