Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c4ded2 commit 6ee0480Copy full SHA for 6ee0480
3 files changed
Lib/repr.py
@@ -7,6 +7,7 @@ def __init__(self):
7
self.maxlevel = 6
8
self.maxtuple = 6
9
self.maxlist = 6
10
+ self.maxarray = 5
11
self.maxdict = 4
12
self.maxstring = 30
13
self.maxlong = 40
@@ -48,6 +49,23 @@ def repr_list(self, x, level):
48
49
s = s + self.repr1(x[i], level-1)
50
if n > self.maxlist: s = s + ', ...'
51
return '[' + s + ']'
52
+
53
+ def repr_array(self, x, level):
54
+ n = len(x)
55
+ header = "array('%s', [" % x.typecode
56
+ if n == 0:
57
+ return header + "])"
58
+ if level <= 0:
59
+ return header + "...])"
60
+ s = ''
61
+ for i in range(min(n, self.maxarray)):
62
+ if s:
63
+ s += ', '
64
+ s += self.repr1(x[i], level-1)
65
+ if n > self.maxarray:
66
+ s += ', ...'
67
+ return header + s + "])"
68
69
def repr_dict(self, x, level):
70
n = len(x)
71
if n == 0: return '{}'
Lib/test/test_repr.py
@@ -34,6 +34,8 @@ def test_string(self):
34
eq(r(s), expected)
35
36
def test_container(self):
37
+ from array import array
38
39
eq = self.assertEquals
40
# Tuples give up after 6 elements
41
eq(r(()), "()")
@@ -56,6 +58,16 @@ def test_container(self):
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):
72
73
eq(r(123), repr(123))
Misc/NEWS
@@ -145,6 +145,9 @@ Extension modules
145
Library
146
-------
147
148
+- array.array was added to the types repr.py knows about (see
149
+ <http://www.python.org/sf/680789>).
150
151
- The new pickletools.py contains lots of documentation about pickle
152
internals, and supplies some helpers for working with pickles, such as
153
a symbolic pickle disassembler.
0 commit comments