From 6ee0480521901d3e84769d1590603f89efd456a4 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Wed, 5 Feb 2003 18:29:34 +0000 Subject: [680789] Debug with long array takes forever Added array.array to the types repr.py knows about, after a suggestion from Jurjen N.E. Bos. --- Lib/repr.py | 18 ++++++++++++++++++ Lib/test/test_repr.py | 12 ++++++++++++ Misc/NEWS | 3 +++ 3 files changed, 33 insertions(+) diff --git a/Lib/repr.py b/Lib/repr.py index c69ce28..0431857 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -7,6 +7,7 @@ class Repr: self.maxlevel = 6 self.maxtuple = 6 self.maxlist = 6 + self.maxarray = 5 self.maxdict = 4 self.maxstring = 30 self.maxlong = 40 @@ -48,6 +49,23 @@ class Repr: s = s + self.repr1(x[i], level-1) if n > self.maxlist: s = s + ', ...' return '[' + s + ']' + + def repr_array(self, x, level): + n = len(x) + header = "array('%s', [" % x.typecode + if n == 0: + return header + "])" + if level <= 0: + return header + "...])" + s = '' + for i in range(min(n, self.maxarray)): + if s: + s += ', ' + s += self.repr1(x[i], level-1) + if n > self.maxarray: + s += ', ...' + return header + s + "])" + 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 47ec07c..29e1687 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -34,6 +34,8 @@ class ReprTests(unittest.TestCase): eq(r(s), expected) def test_container(self): + from array import array + eq = self.assertEquals # Tuples give up after 6 elements eq(r(()), "()") @@ -56,6 +58,16 @@ class ReprTests(unittest.TestCase): d['arthur'] = 1 eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}") + # array.array after 5. + eq(r(array('i')), "array('i', [])") + eq(r(array('i', [1])), "array('i', [1])") + eq(r(array('i', [1, 2])), "array('i', [1, 2])") + eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])") + eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])") + eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])") + eq(r(array('i', [1, 2, 3, 4, 5, 6])), + "array('i', [1, 2, 3, 4, 5, ...])") + def test_numbers(self): eq = self.assertEquals eq(r(123), repr(123)) diff --git a/Misc/NEWS b/Misc/NEWS index 67e84df..25cbe69 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -145,6 +145,9 @@ Extension modules Library ------- +- array.array was added to the types repr.py knows about (see + ). + - The new pickletools.py contains lots of documentation about pickle internals, and supplies some helpers for working with pickles, such as a symbolic pickle disassembler. -- cgit v0.12