[Python-ideas] Draft PEP on string interpolation

Eric V. Smith eric at trueblade.com
Tue Aug 25 20:36:54 CEST 2015


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

On 08/24/2015 08:20 PM, Barry Warsaw wrote:
> On Aug 24, 2015, at 11:55 AM, Eric V. Smith wrote:
> 
>> I should have added: this is for i-strings that look like PEP 
>> 498's f-strings. I'm not trying to jump to conclusions about the 
>> syntax:
> 
> I remember something else about $-strings, based on Mailman's 
> experience. Originally we also used %(foo)s strings, but when that 
> reached the breaking point (and PEP 292 was implemented), we 
> changed to $-strings.  At that point we had to provide an upgrade 
> path for settings with the original %-strings.
> 
> It turns out to not be too difficult to translate between them.
> It would probably not be difficult to translate from $foo to {foo} 
> either, so with a properly defined hook, the porcelain could use 
> $-strings while all the underlying machinery could still use 
> {}-strings.  It would probably have to be roughly limited to
> simple name lookups with dot-chasing, and maybe it's not worth it.

In https://bitbucket.org/ericvsmith/istring, in i18n.py, I've added
the awesomely named convert_istring_format_to_dollar_format(). It also
checks that you've only used identifiers and not specified a
format_spec or a conversion character (exact specs TBD). I've not
implemented the reverse function. I imagine you'd convert to $ format
as part of extracting the strings from the source, do the translation,
then convert back as part of building the translation database.

It also shows how to implement _() with i-strings, including safe
substitution required by a bad translation.

I also have examples for logging and building up regex's from
i-strings. I'm mainly using this to investigate the best API for
i-strings. So far, I just have one method, join, that takes some
callbacks. It also lets you substitute alternate strings, as needed
for the _() examples.

But this is all just an experiment. I'm not sold at all on the concept
of i-strings (and even less so on the nearly equivalent e-strings).

Eric.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)

iQEcBAEBAgAGBQJV3LXGAAoJENxauZFcKtNxtu8H/1Sqrr8gyDIQ5piBPj77Hh3E
285Mmk9wrqgd9Xl3dLJBIb5p0H6GvMQi3DezGHDIBpqPBQneA+1cNpMuFJL07WKw
tDXxsqacsiXPdxA9qx+iLP6cb1mwpsC3OtURZDPeVZPU6Ic/aIRk1DdShBleIlH6
v/X6BMQz0mrI/PpI364jo39hUr81iU0XWExeiigOWZu//nkjV+WeOUbdpQCBYl2M
VEpGl5f2TlY0O85MBFdPc8RKGnROq7OyLhi8SvY+gknGPhwMI+gGeh19vyUPpKfW
CEqDju5KWmYW7sCJ0e7JQ+Z5IvSBIAgQoJmfxibW4rhLbc73YwlaGaoYwt831lM=
=Drm6
-----END PGP SIGNATURE-----


More information about the Python-ideas mailing list