[Python-ideas] Let’s make escaping in f-literals impossible
Stephen J. Turnbull
turnbull.stephen.fw at u.tsukuba.ac.jp
Sat Aug 20 05:29:30 EDT 2016
C Anthony Risinger writes:
> The only time I personally use a different quote is when it somehow
> makes the data more amenable to the task at hand. The data! The
> literal data! Not the expressions I'm conveniently inlining with
> the help of f-strings.
You do *not* know that yet! *Nobody* does. Nobody has yet written an
f-string in production code, let alone read thousands and written
hundreds. Can you be sure that after you write a couple dozen
f-strings you won't find that such "quote context" is carried over
naturally from the way you write other strings? (Eg, because "I'm
still in a string" is signaled by the highlighting of the surrounding
stringish text.)
I think the proposed changes to the PEP fall into the "Sometimes never
is better than *right* now" category. The arguments I've seen so far
are plausible but not founded in experience: it could easily go the
other way, and I don't see potential for true disaster.
> If I have to water it down for people to find it acceptable (such
> as creating simpler variables ahead-of-time) I'd probably just keep
> using .format(...). Because what I have gained with an f-string?
I don't see a problem if you choose not to write f-strings. Would
other people using that convention be hard for you to *read*?
> Not just because it's at odds with other languages, but because
> it's at odds with what the editor is telling the user (free-form
> expression).
There are no editors that will tell you such a thing yet.
And if you trust an editor that *does* tell you that it's a free-form
expression and use the same kind of quote that delimits the f-string,
you won't actually create a syntax error. You're merely subject to
the same kind of "problem" that you have if you don't write PEP8
conforming code.
Regards,
More information about the Python-ideas
mailing list