[Python-ideas] String interpolation for all literal strings

Nathaniel Smith njs at pobox.com
Fri Aug 7 11:03:35 CEST 2015


On Fri, Aug 7, 2015 at 1:49 AM, Guido van Rossum <guido at python.org> wrote:
> On Fri, Aug 7, 2015 at 9:33 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>
>> We could potentially make f-strings translation friendly by
>> introducing a bit of indirection into the f-string design: an
>> __interpolate__ builtin, along the lines of __import__.
>
>
> This seems interesting, but doesn't it require sys._getframe() or similar
> again? Translations may need to reorder variables. (Or even change the
> expressions? E.g. to access odd plurals?)
>
> The sys._getframe() requirement (if true) would kill this idea thoroughly
> for me.

AFAICT sys._getframe is unneeded -- I understand Nick's suggestion to
be that we desugar f"..." to:

   __interpolate__("...", locals(), globals())

with the reference to __interpolate__ resolved using the usual lookup
rules (locals -> globals -> builtins).

-n

-- 
Nathaniel J. Smith -- http://vorpus.org


More information about the Python-ideas mailing list