# HG changeset patch # User Yuya Nishihara <y...@tcha.org> # Date 1517041885 -32400 # Sat Jan 27 17:31:25 2018 +0900 # Node ID d6dc55d17ec2df28f544701cb97dce4a7641a1ed # Parent 6ac5670c4d6cf51930af9bd63981c3f5ef986699 py3: always drop b'' prefix from repr() of bytestr
Perhaps this is what we wanted for py2-3 compatibility. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1563,17 +1563,9 @@ def export(repo, revs, fntemplate='hg-%h 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 --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -88,7 +88,7 @@ if ispy3: """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 @@ if ispy3: ... 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 @@ if ispy3: 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) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel