[Python-ideas] f-string literals by default?

Joseph Jevnik joejev at gmail.com
Tue Dec 5 16:22:11 EST 2017


This would break code that uses str.format everywhere for very little benefit.

On Tue, Dec 5, 2017 at 4:19 PM, 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.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list