diff options
-rw-r--r-- | Lib/repr.py | 8 | ||||
-rw-r--r-- | Lib/test/test_repr.py | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Lib/repr.py b/Lib/repr.py index a137306..7c0016b 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -15,6 +15,7 @@ class Repr: self.maxdict = 4 self.maxset = 6 self.maxfrozenset = 6 + self.maxdeque = 6 self.maxstring = 30 self.maxlong = 40 self.maxother = 20 @@ -37,7 +38,7 @@ class Repr: s = s[:i] + '...' + s[len(s)-j:] return s - def _repr_iterable(self, x, level, left, right, maxiter, final=''): + def _repr_iterable(self, x, level, left, right, maxiter, trail=''): n = len(x) if level <= 0 and n: s = '...' @@ -47,7 +48,7 @@ class Repr: pieces = [repr1(elem, newlevel) for elem in islice(x, maxiter)] if n > maxiter: pieces.append('...') s = ', '.join(pieces) - if n == 1 and final: s += final + if n == 1 and trail: right = trail + right return '%s%s%s' % (left, s, right) def repr_tuple(self, x, level): @@ -67,6 +68,9 @@ class Repr: return self._repr_iterable(x, level, 'frozenset([', '])', self.maxfrozenset) + def repr_deque(self, x, level): + return self._repr_iterable(x, level, 'deque([', '])', self.maxdeque) + def repr_dict(self, x, level): n = len(x) if n == 0: return '{}' diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index b00f328..4ded484 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -35,6 +35,7 @@ class ReprTests(unittest.TestCase): def test_container(self): from array import array + from collections import deque eq = self.assertEquals # Tuples give up after 6 elements @@ -65,6 +66,9 @@ class ReprTests(unittest.TestCase): eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])") eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])") + # collections.deque after 6 + eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])") + # Dictionaries give up after 4. eq(r({}), "{}") d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4} |