[Python-ideas] Draft2 PEP on string interpolation

Guido van Rossum guido at python.org
Thu Aug 27 20:27:33 CEST 2015


On Wed, Aug 26, 2015 at 9:40 PM, Mike Miller <python-ideas at mgmiller.net>
wrote:

> With the major design decisions made, behold version 2 of my draft PEP on
> string interpolation.
>
> It's now significantly shorter due to removal of most of the i18n related
> discussion, pruning, as well as simplification of the prose itself.  I
> don't expect many changes from here on:
>
>     https://bitbucket.org/mixmastamyk/docs/src/default/pep/pep-05XX.rst
>

I'm confused by this proposal. There are many paragraphs about motivation,
philosophy, other languages, etc., but the proposal itself seems to be
poorly specified. E.g. I couldn't figure out what code should be produced
by:

  a = e"Sliced {n} onions in {t1-t0:.3f} seconds."

Generalizing from the only example in the specification, this would become:

  a = est("Sliced {n} onions in {t1-t0:.3f} seconds", n=n, t1-t0=t1-t0)

which is invalid syntax. Similarly, I don't see how e.g. the following
could be rendered correctly:

  a = e"Three random numbers: {rand()}, {rand()}, {rand()}."

I also don't understand the claim that no str(estr) is necessary to render
the result -- the estr implementation given at
https://bitbucket.org/mixmastamyk/docs/src/default/pep/estring_demo.py has
a __str__ method that renders the .rendered attribute, but without the
str() call the type of 'a' in the above examples would not be str, and
various things that operate on strings (e.g. regular expression searches)
would not work. A solution might be to make estr a subclass of str, but
nothing in the PEP suggests that you have even considered this problem.
(The only hint I can find is the comment "more magic-methods to be
implemented here, to improve str compatibility" in your demo
implementation, but without subclassing str this is not enough.)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150827/d92066fc/attachment.html>


More information about the Python-ideas mailing list