[Python-ideas] String interpolation for all literal strings

Eric V. Smith eric at trueblade.com
Thu Aug 6 10:27:49 CEST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/5/2015 3:53 PM, Barry Warsaw wrote:
> On Aug 05, 2015, at 03:34 PM, Yury Selivanov wrote:
> 
>> On 2015-08-05 2:56 PM, Eric V. Smith wrote:
>>> The concept would be that all strings are scanned for \{ and }
>>> pairs.
> 
> I think it's a very interesting idea too, although the devil is in
> the details.  Since this will be operating on string literals,
> they'd be scanned at compile time right?

Yes, they'd be scanned at compile time. As the AST is being built, the
string would be parsed and transformed into the AST for the
appropriate function calls.

> Agreed that raw strings probably shouldn't be scanned.  Since it
> may happen that some surprising behavior occurs (long after it's
> past __future__), there should be some way to prevent scanning.  To
> me that either means r'' strings don't get scanned or f'' is
> required.

I've come around to raw strings not being scanned.

> I'm still unclear on what the difference would be between f''
> strings and these currently mythical scanned-strings are, but I'll
> wait for the PEP.

Well, that's a not-fully-specified idea, as of now.

>> Have you considered using '#{..}' syntax (used by Ruby and 
>> CoffeeScript)?
>> 
>> '\{..}' feels unbalanced and weird.
> 
> As it does for me.  Let's see what particular color Eric reaches
> for.

I agree with Guido that we use \ to mean "something special happens
with the next character". And we use braces for str.format.

Although ${...} also tugs at my heart strings.

Eric.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJVwxqFAAoJENxauZFcKtNxj/MH/1qIW9LN92KxGc16iCJ5enwx
tXxzvu+6ki2iXphxN9AKm3l7XIR4QFGBkXEA2HBF5JaBpzp76/Ofvso98EfNKXk8
R7SfvfYXt3SPtySgjR0Gt/5eOt5VxAXYq9FTSfxz4EK/IGXyk8zoGpQsmFxvh05X
lm239Q8wliuFiMzLPUWdwp1bfXdgpyQ+jw7AA5FGk6kMLzsGGX4OLGnJEhXOHIG9
sESJKhpHhuBBJ5pUZTpygaeSpMDLURH7M40MTEt/bWyYHCAWNxfgPxRp2ml18otJ
dMlNL++BNuA3YFsq0UpYX61BQV37A7AiFfy+arA5HkSU+gU7tRQwzrqgHLLLKNY=
=V+8l
-----END PGP SIGNATURE-----


More information about the Python-ideas mailing list