py3: always drop b'' prefix from repr() of bytestr
authorYuya Nishihara <yuya@tcha.org>
Sat, 27 Jan 2018 17:31:25 +0900
changeset 35903 1a31111e6239
parent 35902 2da4144e6716
child 35904 fc44c2657dc5
py3: always drop b'' prefix from repr() of bytestr Perhaps this is what we wanted for py2-3 compatibility.
mercurial/cmdutil.py
mercurial/pycompat.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):
--- 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)