# HG changeset patch # User Gregory Szorc # Date 2018-04-13 03:42:42 # Node ID 68132a95df31a83b9cd680df56b62a531fb22d06 # Parent 1edf3738e000023fe526705ab675d9577a8aff75 stringutil: support more types with pprint() bytearray wasn't working. Integers and floats were not being formatted. I /think/ %f is portable across both Python 2 and 3, as it should default to 6 decimal points on each. Differential Revision: https://phab.mercurial-scm.org/D3302 diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py --- a/mercurial/utils/stringutil.py +++ b/mercurial/utils/stringutil.py @@ -25,8 +25,12 @@ from .. import ( def pprint(o): """Pretty print an object.""" - if isinstance(o, (bytes, bytearray)): + if isinstance(o, bytes): return "b'%s'" % escapestr(o) + elif isinstance(o, bytearray): + # codecs.escape_encode() can't handle bytearray, so escapestr fails + # without coercion. + return "bytearray['%s']" % escapestr(bytes(o)) elif isinstance(o, list): return '[%s]' % (b', '.join(pprint(a) for a in o)) elif isinstance(o, dict): @@ -34,6 +38,10 @@ def pprint(o): '%s: %s' % (pprint(k), pprint(v)) 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 else: raise error.ProgrammingError('do not know how to format %r' % o)