# HG changeset patch # User Yuya Nishihara # Date 1517041885 -32400 # Node ID 1a31111e6239a2eb841a5dce5e1cf8212c54bf33 # Parent 2da4144e6716063e83ab291a0292a1a9e8cb88ac py3: always drop b'' prefix from repr() of bytestr Perhaps this is what we wanted for py2-3 compatibility. diff -r 2da4144e6716 -r 1a31111e6239 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Sat Jan 27 17:13:51 2018 +0900 +++ b/mercurial/cmdutil.py Sat Jan 27 17:31:25 2018 +0900 @@ -1563,17 +1563,9 @@ if fo is not None: fo.close() -class _regrettablereprbytes(bytes): - """Bytes subclass that makes the repr the same on Python 3 as Python 2. - - This is a huge hack. - """ - def __repr__(self): - return repr(pycompat.sysstr(self)) - def _maybebytestr(v): - if pycompat.ispy3 and isinstance(v, bytes): - return _regrettablereprbytes(v) + if isinstance(v, bytes): + return pycompat.bytestr(v) return v def showmarker(fm, marker, index=None): diff -r 2da4144e6716 -r 1a31111e6239 mercurial/pycompat.py --- a/mercurial/pycompat.py Sat Jan 27 17:13:51 2018 +0900 +++ b/mercurial/pycompat.py Sat Jan 27 17:31:25 2018 +0900 @@ -88,7 +88,7 @@ """A bytes which mostly acts as a Python 2 str >>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1) - (b'', b'foo', b'ascii', b'1') + ('', 'foo', 'ascii', '1') >>> s = bytestr(b'foo') >>> assert s is bytestr(s) @@ -98,7 +98,7 @@ ... def __bytes__(self): ... return b'bytes' >>> bytestr(bytesable()) - b'bytes' + 'bytes' There's no implicit conversion from non-ascii str as its encoding is unknown: @@ -154,6 +154,9 @@ def __iter__(self): return iterbytestr(bytes.__iter__(self)) + def __repr__(self): + return bytes.__repr__(self)[1:] # drop b'' + def iterbytestr(s): """Iterate bytes as if it were a str object of Python 2""" return map(bytechr, s)