[Python-Dev] PEP 498: Literal String Interpolation

Eric V. Smith eric at trueblade.com
Mon Aug 31 23:07:50 CEST 2015

On 8/31/2015 4:08 PM, Yury Selivanov wrote:
> On 2015-08-31 9:10 AM, Nick Coghlan wrote:
>> On 30 August 2015 at 23:41, Eric V. Smith <eric at trueblade.com> wrote:
>>> Note there's a companion PEP 501 which extends this idea by delaying
>>> converting the expression into a string. This allows for more control
>>> over how the expressions are converted in to strings, and allows for
>>> non-string conversions as well.
>> For the benefit of folks that weren't following the (many) iterations
>> on python-ideas: PEP 501's general purpose string interpolation
>> started out as a competitor to 498, but as the discussion continued
>> and my ideas started to converge more and more with Eric's, I
>> eventually realised it made more sense as an optional extension to PEP
>> 498 that exposed the inner workings of the scope aware interpolation
>> machinery to Python code.
> If PEP 501 is an extension to PEP 498, then the proposal
> is to add i'' prefix *in addition* to f'', right?

That would be my intention, yes. Your only other choice to get plain
strings from a template would be to always say format(i'{expression}'),
which I don't think is an improvement.

> If so, I think it might be confusing to a lot of people on
> what prefix should be used and when.  I think it's too easy
> for an average user to write ``os.system(f'...')`` and think
> that their code is fine, instead of ``os.system(i'...')``.
> What's worse, is that there is no way for ``os.system()``
> to reject the former use.

That's all correct. I have to say that I like PEP 501 mainly for its
non-string use cases. That is, interpolators that don't produce strings.
Note that this isn't possible with PEP 502's proposal.

> Second, given that we use "f" for "formatted", using "i"
> for "interpolated template" is a bit confusing.  Can
> we use "t" ("template strings")?

I don't really care so much about the prefixes. I'd be okay with PEP 498
being either 'f', 'i', or 't'. I could warm up to 't' easier than 'i'.


More information about the Python-Dev mailing list