[Python-ideas] Draft2 PEP on string interpolation

Eric V. Smith eric at trueblade.com
Thu Aug 27 19:27:05 CEST 2015


On 08/27/2015 11:22 AM, Mike Miller wrote:
> 
> On 08/27/2015 06:36 AM, Cody Piersall wrote:
>>
>> Is the Draft PEP column of the table supposed to have both "Immediate
>> Render"
>> and "Deferred Render" as "Yes"? I'm hoping that's a typo, otherwise I
>> don't
>> understand what it means at all.
> 
> Yes, it supports both.  By storing all inputs to the object, it can be
> rendered again, with optional changes such as overriding a value, or
> escaping the input.

The problem with this auto-rendering is that the format_spec and
conversion character have to make sense to __format__. For example, you
couldn't do this, if value were a string:

to_html(e'<p>{value:raw}</p>')

Imagine that ":raw" is interpreted by to_html() to mean that the string
does not get html escaped.

With PEP 501, the format_spec and conversion are opaque to the i-string
machinery, and are only interpreted by the custom interpolation function
(here, to_html()).

Eric.



More information about the Python-ideas mailing list