Skip to content
Snippets Groups Projects
Commit f0827211 authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

py3: build repr() of smartset as bytes then convert to str

This isn't pretty, but we have no way to teach Python 3 that our __repr__()
would like to return a byte string.
parent 72de5c50
No related merge requests found
......@@ -8,4 +8,5 @@
from __future__ import absolute_import
from . import (
encoding,
error,
......@@ -11,4 +12,5 @@
error,
pycompat,
util,
)
......@@ -19,7 +21,7 @@
type(r) example
======== =================================
tuple ('<not %r>', other)
str '<branch closed>'
bytes '<branch closed>'
callable lambda: '<branch %r>' % sorted(b)
object other
======== =================================
......@@ -28,8 +30,8 @@
return ''
elif isinstance(r, tuple):
return r[0] % r[1:]
elif isinstance(r, str):
elif isinstance(r, bytes):
return r
elif callable(r):
return r()
else:
......@@ -32,8 +34,11 @@
return r
elif callable(r):
return r()
else:
return repr(r)
return pycompat.sysbytes(repr(r))
def _typename(o):
return pycompat.sysbytes(type(o).__name__).lstrip('_')
class abstractsmartset(object):
......@@ -384,6 +389,7 @@
s._ascending = self._ascending
return s
@encoding.strmethod
def __repr__(self):
d = {None: '', False: '-', True: '+'}[self._ascending]
s = _formatsetrepr(self._datarepr)
......@@ -394,8 +400,8 @@
# We fallback to the sorted version for a stable output.
if self._ascending is not None:
l = self._asclist
s = repr(l)
return '<%s%s %s>' % (type(self).__name__, d, s)
s = pycompat.sysbytes(repr(l))
return '<%s%s %s>' % (_typename(self), d, s)
class filteredset(abstractsmartset):
"""Duck type for baseset class which iterates lazily over the revisions in
......@@ -505,4 +511,5 @@
pass
return x
@encoding.strmethod
def __repr__(self):
......@@ -508,5 +515,5 @@
def __repr__(self):
xs = [repr(self._subset)]
xs = [pycompat.sysbytes(repr(self._subset))]
s = _formatsetrepr(self._condrepr)
if s:
xs.append(s)
......@@ -510,7 +517,7 @@
s = _formatsetrepr(self._condrepr)
if s:
xs.append(s)
return '<%s %s>' % (type(self).__name__, ', '.join(xs))
return '<%s %s>' % (_typename(self), ', '.join(xs))
def _iterordered(ascending, iter1, iter2):
"""produce an ordered iteration from two iterators with the same order
......@@ -755,5 +762,6 @@
self.reverse()
return val
@encoding.strmethod
def __repr__(self):
d = {None: '', False: '-', True: '+'}[self._ascending]
......@@ -758,6 +766,6 @@
def __repr__(self):
d = {None: '', False: '-', True: '+'}[self._ascending]
return '<%s%s %r, %r>' % (type(self).__name__, d, self._r1, self._r2)
return '<%s%s %r, %r>' % (_typename(self), d, self._r1, self._r2)
class generatorset(abstractsmartset):
"""Wrap a generator for lazy iteration
......@@ -918,5 +926,6 @@
return self.last()
return next(it(), None)
@encoding.strmethod
def __repr__(self):
d = {False: '-', True: '+'}[self._ascending]
......@@ -921,6 +930,6 @@
def __repr__(self):
d = {False: '-', True: '+'}[self._ascending]
return '<%s%s>' % (type(self).__name__.lstrip('_'), d)
return '<%s%s>' % (_typename(self), d)
class _generatorsetasc(generatorset):
"""Special case of generatorset optimized for ascending generators."""
......@@ -1087,5 +1096,6 @@
y = max(self._end - start, self._start)
return _spanset(x, y, self._ascending, self._hiddenrevs)
@encoding.strmethod
def __repr__(self):
d = {False: '-', True: '+'}[self._ascending]
......@@ -1090,7 +1100,6 @@
def __repr__(self):
d = {False: '-', True: '+'}[self._ascending]
return '<%s%s %d:%d>' % (type(self).__name__.lstrip('_'), d,
self._start, self._end)
return '<%s%s %d:%d>' % (_typename(self), d, self._start, self._end)
class fullreposet(_spanset):
"""a set containing all revisions in the repo
......@@ -1123,7 +1132,7 @@
def prettyformat(revs):
lines = []
rs = repr(revs)
rs = pycompat.sysbytes(repr(revs))
p = 0
while p < len(rs):
q = rs.find('<', p + 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment