diff mercurial/pycompat.py @ 35943:1a31111e6239

py3: always drop b'' prefix from repr() of bytestr Perhaps this is what we wanted for py2-3 compatibility.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 27 Jan 2018 17:31:25 +0900
parents e66d6e938d2d
children fc44c2657dc5
line wrap: on
line diff
--- 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)