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

Augie Fackler raf at durin42.com
Wed May 31 19:15:43 UTC 2017


# HG changeset patch
# User Augie Fackler <raf at 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.

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


More information about the Mercurial-devel mailing list