Patchwork [1,of,2,v2,py3] help: convert flag default to bytes portably

login
register
mail settings
Submitter Augie Fackler
Date May 31, 2017, 7:15 p.m.
Message ID <21fdfbb91fa693787db3.1496258143@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/21094/
State Accepted
Headers show

Comments

Augie Fackler - May 31, 2017, 7:15 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496000969 14400
#      Sun May 28 15:49:29 2017 -0400
# Node ID 21fdfbb91fa693787db38decfc21962d1e004e28
# Parent  e4d0b2efb8b5aea10d1880d602c7d7b3a32c25a3
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.
Yuya Nishihara - June 1, 2017, 2:52 p.m.
On Wed, 31 May 2017 15:15:43 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1496000969 14400
> #      Sun May 28 15:49:29 2017 -0400
> # Node ID 21fdfbb91fa693787db38decfc21962d1e004e28
> # Parent  e4d0b2efb8b5aea10d1880d602c7d7b3a32c25a3
> help: convert flag default to bytes portably

Queued these, thanks.

Patch

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.bytestr(default)
 
         if isinstance(default, list):
             lo += " %s [+]" % optlabel