[Python-Dev] PEP-498: Literal String Formatting

Barry Warsaw barry at python.org
Mon Aug 17 16:50:18 CEST 2015


On Aug 17, 2015, at 11:02 AM, Paul Moore wrote:

>    print(f"Iteration {n}: Took {end-start) seconds")

This illustrates (more) problems I have with arbitrary expressions.

First, you've actually made a typo there; it should be "{end-start}" -- notice
the trailing curly brace.  Second, what if you typoed that as "{end_start}"?
According to PEP 498 the original typo above should trigger a SyntaxError and
the second a run-time error (NameError?).  But how will syntax highlighters
and linters help you discover your bugs before you've even saved the file?
Currently, a lot of these types of problems can be found much earlier on
through the use of such linters.  Putting arbitrary expressions in strings
will just hide them to these tools for the foreseeable future.  I have a hard
time seeing how Emacs's syntax highlighting could cope with it for example.

Cheers,
-Barry


More information about the Python-Dev mailing list