> On May 29, 2017, at 12:37 PM, Martijn Pieters <m...@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 <r...@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <r...@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@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
> 
> 
> 
> -- 
> Martijn Pieters

_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to