<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Aug 22, 2015 at 3:09 AM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 22 August 2015 at 15:52, Mike Miller <<a href="mailto:python-ideas@mgmiller.net">python-ideas@mgmiller.net</a>> wrote:<br>
> Hi,<br>
><br>
> I'm not sure that's the case any more, after reading the threads here this<br>
> week there are numerous difficulties with trying to reconcile both use<br>
> cases, and didn't get the feeling anyone has an elegant solution to them.<br>
><br>
> We could implement f'' and (i'', aka t'') using either syntax of course,<br>
> parsing variables from the string, but choosing translation with<br>
> str.format() seems to cause several more issues than (string.Template() and<br>
> a bit of inconsistency does).<br>
><br>
> Which syntax would you rather have for translation? (Knowing that you might<br>
> give a different answer for standard interpolation.)<br>
<br>
</span>I just pushed a major rewrite of PEP 501 based on the discussions<br>
since the initial version of that and PEP 498 went online:<br>
<a href="https://www.python.org/dev/peps/pep-0501/" rel="noreferrer" target="_blank">https://www.python.org/dev/peps/pep-0501/</a><br>
<br>
It switches to using a magic method and explicitly named interpolator<br>
in interpolation expressions, with "!str" being the interpolator<br>
reference for default string formatting. From a motivation<br>
perspective, while i18n remains a consideration, more easily<br>
addressing the risk of code injection attacks against naive use of<br>
string interpolation when generating database queries, shell commands<br>
or HTML pages now provides a stronger motivation making the<br>
interpolation semantics extensible.<br>
<br>
Writing a custom interpolator (including for i18n) becomes as simple as doing:<br>
<br>
@interpolator<br>
def my_interpolator(raw_template, parsed_fields, field_values):<br>
...<br>
<br>
While using it then looks like:<br>
<br>
result = !my_interpolator "This has $values $mixed into it"<br>
<br>
(Similar to yield, it is proposed that interpolation expressions would<br>
require parentheses when embedded inside a larger expression)<br></blockquote><div><br></div><div>1. That's an entirely different proposal, you're just reusing the PEP number.<br><br></div><div>2. Have I died and gone to Perl?<br></div></div><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>