[PATCH 01 of 10 py3] help: convert flag default to bytes portably

Augie Fackler raf at durin42.com
Mon May 29 12:42:21 EDT 2017


> On May 29, 2017, at 12:40 PM, Martijn Pieters <mj at zopatista.com> wrote:
> 
> Right, indeed. Would it be worth the effort to have `_(...)` return an object with a custom `%` for cases like these? Not sure what this would look like though.

My bias is “no” because that feels a little too clever.

> 
> On 29 May 2017 at 17:38, Augie Fackler <raf at durin42.com <mailto:raf at durin42.com>> wrote:
> 
> > On May 29, 2017, at 12:37 PM, Martijn Pieters <mj at zopatista.com <mailto:mj at zopatista.com>> wrote:
> >
> > So why not use `%r` instead of `%s` so `repr()` is used (or rather, `ascii()` in Python 3)? That way you don't have to use this dance.
> 
> Because then if the default was a bytestring we’d get a b’’ in the output.
> 
> >
> > On 29 May 2017 at 15:32, Augie Fackler <raf at durin42.com <mailto:raf at durin42.com>> wrote:
> > # HG changeset patch
> > # User Augie Fackler <raf at durin42.com <mailto:raf at durin42.com>>
> > # Date 1496000969 14400
> > #      Sun May 28 15:49:29 2017 -0400
> > # Node ID 75e176c753d2c2c7eb5b5c0791bc993160fcb7b1
> > # Parent  aa333c1982abfe12a3940811d07468a286de93db
> > help: convert flag default to bytes portably
> >
> > We were relying on %s using repr on (for example) integer values. Work
> > around that for Python 3 while preserving all the prior magic.
> >
> > diff --git a/mercurial/help.py b/mercurial/help.py
> > --- a/mercurial/help.py
> > +++ b/mercurial/help.py
> > @@ -84,7 +84,11 @@ def optrst(header, options, verbose):
> >              so = '-' + shortopt
> >          lo = '--' + longopt
> >          if default:
> > -            desc += _(" (default: %s)") % default
> > +            # default is of unknown type, and in Python 2 we abused
> > +            # the %s-shows-repr property to handle integers etc. To
> > +            # match that behavior on Python 3, we do str(default) and
> > +            # then convert it to bytes.
> > +            desc += _(" (default: %s)") % pycompat.sysbytes(str(default))
> >
> >          if isinstance(default, list):
> >              lo += " %s [+]" % optlabel
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel at mercurial-scm.org <mailto:Mercurial-devel at mercurial-scm.org>
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel <https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel>
> >
> >
> >
> > --
> > Martijn Pieters
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org <mailto:Mercurial-devel at mercurial-scm.org>
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel <https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel>
> 
> 
> 
> -- 
> Martijn Pieters

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170529/871ced72/attachment.html>


More information about the Mercurial-devel mailing list