Patchwork [1,of,2] stringutil: make pprint() forward uninteresting object to b'%r'

login
register
mail settings
Submitter Yuya Nishihara
Date May 10, 2018, 2:10 p.m.
Message ID <ac6531a127cbc6f4bb24.1525961445@mimosa>
Download mbox | patch
Permalink /patch/31456/
State Accepted
Headers show

Comments

Yuya Nishihara - May 10, 2018, 2:10 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1525953658 -32400
#      Thu May 10 21:00:58 2018 +0900
# Node ID ac6531a127cbc6f4bb2479b7f7805ee70dd45af5
# Parent  8925924750942e596c30062a74eb32db9267412d
stringutil: make pprint() forward uninteresting object to b'%r'

We appear to start using pprint() as a replacement for repr(), so it's
probably safer to support any Python objects instead of complaining about
that.

Patch

diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -40,16 +40,7 @@  def pprint(o, bprefix=True):
             '%s: %s' % (pprint(k, bprefix=bprefix),
                         pprint(v, bprefix=bprefix))
             for k, v in sorted(o.items())))
-    elif isinstance(o, bool):
-        return b'True' if o else b'False'
-    elif isinstance(o, int):
-        return '%d' % o
-    elif isinstance(o, float):
-        return '%f' % o
-    elif o is None:
-        return b'None'
-    else:
-        raise error.ProgrammingError('do not know how to format %r' % o)
+    return pycompat.byterepr(o)
 
 def binary(s):
     """return true if a string is binary data"""