[Python-ideas] f-string literals by default?
rosuav at gmail.com
Tue Dec 5 16:23:33 EST 2017
On Wed, Dec 6, 2017 at 8:19 AM, Neil Schemenauer
<nas-python-ideas at arctrix.com> wrote:
> I think most people who have tried f-strings have found them handy.
> Could we transition to making default string literal into an
> f-string? I think there is a smooth migration path.
> f-strings without embedded expressions already compile to the same
> bytecode as normal string literals. I.e. no overhead. The issue
> will be literal strings that contain the f-string format characters.
> We could add a future import, e.g.
> from __future__ import fstring_literals
> that would make all literal strings in the module into f-strings.
> In some future release, we could warn about literal strings in
> modules without the future import that contain f-string format
> characters. Eventually, we can change the default.
> To make migration easier, we can provide a source-to-source
> translation tool. It is quite simple to do that using
> the tokenizer module.
No. Definitely not. It'd lead to all manner of confusion ("why can't I
put braces in my string?"), and it's unnecessary. When you want
interpolation, you put *one letter* in front of the string, and it
means that most strings aren't magical pieces of executable code. Tiny
advantage, large potential disadvantage.
More information about the Python-ideas