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

Guido van Rossum guido at python.org
Thu Aug 20 18:07:34 CEST 2015


Time to write up a slimmed-down proposal that merges the best ideas from
both PEPs? The first version doesn't have to have a PEP-level document, but
it should clarify the actual proposal by showing the various usage patterns.

On Thu, Aug 20, 2015 at 1:34 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 18 August 2015 at 07:37, Ned Batchelder <ned at nedbatchelder.com> wrote:
> >
> > 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 was hoping to avoid a proliferation of new string prefixes and get
> away with only one :)
>
> However, I like Guido's(?) suggestion of using "_" as the prefix to
> distinguish the i18n runtime translation case from the plain string
> interpolation case, so having both "i" and "iu" invoke str.format,
> "ib" invoke bytes.__mod__, and "_" invoke a __translate__ builtin
> (and/or thread local translation context) seems reasonable.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



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


More information about the Python-ideas mailing list