Current py3k stage and next steps

Renato Cunha renatoc at gmail.com
Thu Jul 1 02:31:39 UTC 2010


On Wed, Jun 30, 2010 at 10:08:47AM -0500, Matt Mackall wrote:
> > What kind of solution do _you_ foresee for the encoding problems?
> 
> Having thought about it a bit more this evening, I think the most
> straightforward approach is:
> 
> a) teach 2to3 to change all strings in the source into bytestrings
> b) fix up the annoying b"A"[0] = 65 behavior
> c) make the minimum amount of other source changes to get it working
> under 3.x 

Just to keep you informed, I'm focusing on a) right now (as this approach
arised in the last meeting). I already have a naïve implementation [1] and am
working on removing the obvious bugs this solution might generate
(os.environ[b'whatever'] comes to mind).

Actually, I'm leaning towards stealing some ideas from Martin v. Löwis'
compatibility layer for c) and using that layer in a).

I still don't really know how I'll tackle b). As always, I'm open to
suggestions.

> > What about extending _ , or wrapping it, to pass arguments around?
> > 
> > Something like
> > 
> > def __(gettextkey, *args):
> >     def encodeifunicode(arg):
> >         if isinstance(arg, unicode):
> >             return arg.encode("utf8")
> >         else:
> >             # by default, str objects we have around should be
> > utf8-encoded strings
> 
> We actually want things in the local encoding, but..
> 
> >             return arg
> > 
> >     # assumption: _() returns utf8-encoded strings
> >     _(gettextkey) % tuple(map(encodeifunicode, args))
> > 
> > So we would use
> >    __("foo %s bar %s", rawbytes, mayberawbytes)
> > instead of
> >    _("foo %s bar %s") % (rawbytes, mayberawbytes)
> 
> Hmm, not completely horrible. It solves the % problem reasonably well
> (though note your implementation is only correct for %s).
> But that still leaves the + problem.

Even though this problem still exists, I like Nicolas' suggestion.

[1] http://bitbucket.org/trovao/hg-py3k-patches/src/tip/hg2to3.py.diff (yeah,
it's a bit unreadable right now)

Regards,
-- 
Renato Cunha <http://renatocunha.com>
Blog: http://valedotrovao.com
"If more of us valued food and cheer
and song above hoarded gold,
it would be a merrier world.
              -- J. R. R. Tolkien


More information about the Mercurial-devel mailing list