[Python-ideas] Fix the DRY problem (was Re: PEP 501 - i18n with marked strings)

Ned Batchelder ned at nedbatchelder.com
Mon Aug 17 23:37:03 CEST 2015


On 8/17/15 11:51 AM, Barry Warsaw wrote:
> One of the things I've mentioned to Nick about PEP 501 is the difference
> between i"foo" and iu"foo".  The former gets mapped to __interpolate__() while
> the latter gets mapped to __interpolateu__().  Nick makes the case for this
> distinction based on the ability to override __interpolate__() in the local
> namespace to implement i18n, whereas __interpolateu__() - while technically
> still able to override - would generally just be left to the "normal" non-i18n
> interpolation.
>
> I countered with a proposal that a context manager could be used, but Nick
> points out that you can't really *unbind* __interpolate__() when the context
> manager exits.
>
> This still seems weird to me.  There's no distinction in Python 3 between
> "foo" and u"foo" with the latter having been re-added to aid in migrations
> between Python 2 and 3.  But with PEP 501, this introduces a functional
> distinction between i"foo" and iu"foo" (and ui"foo"?).  It's handy, but seems
> to be a fairly significant difference from the current use if u-prefixes.  I'm
> sympathetic but still skeptical. ;)

I agree that this "one weird trick" of distinguishing between i"" and 
iu"" is really unfortunate. As you say, in Python 3, "foo" and u"foo" 
are the same, so why should i"" and iu"" be different?

I understand the appeal of interpolated strings, but can we retain some 
measure of "explicit is better than implicit"?  If i18n considerations 
are this important (and I agree that they are), let's take them 
seriously enough to give them real syntax.

--Ned.


More information about the Python-ideas mailing list