[pypy-commit] pypy release-1.6.x: The constructor can take a different array; but the precise
arigo
noreply at buildbot.pypy.org
Tue Aug 16 14:15:09 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: release-1.6.x
Changeset: r46540:0570e6f6ecf0
Date: 2011-08-16 14:18 +0200
http://bitbucket.org/pypy/pypy/changeset/0570e6f6ecf0/
Log: The constructor can take a different array; but the precise checking
of the array type is still valid for the app-level extend() method.
Bah. (transplanted from f277de1c5fcdf0e9fa1fd0a86b5149675a2c8524)
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -38,12 +38,10 @@
w_initializer = __args__.arguments_w[0]
if space.type(w_initializer) is space.w_str:
a.fromstring(space.str_w(w_initializer))
- elif space.type(w_initializer) is space.w_unicode:
- a.fromsequence(w_initializer)
elif space.type(w_initializer) is space.w_list:
a.fromlist(w_initializer)
else:
- a.extend(w_initializer)
+ a.extend(w_initializer, True)
break
else:
msg = 'bad typecode (must be c, b, B, u, h, H, i, I, l, L, f or d)'
@@ -287,7 +285,7 @@
self.setlen(s)
raise
- def extend(self, w_iterable):
+ def extend(self, w_iterable, accept_different_array=False):
space = self.space
if isinstance(w_iterable, W_Array):
oldlen = self.len
@@ -300,7 +298,8 @@
self.buffer[oldlen + i] = w_iterable.buffer[i]
i += 1
self.setlen(oldlen + i)
- elif isinstance(w_iterable, W_ArrayBase):
+ elif (not accept_different_array
+ and isinstance(w_iterable, W_ArrayBase)):
msg = "can only extend with array of same kind"
raise OperationError(space.w_TypeError, space.wrap(msg))
else:
diff --git a/pypy/module/array/test/test_array.py b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -64,6 +64,10 @@
assert self.array(tc).typecode == tc
raises(TypeError, self.array, tc, None)
+ a = self.array('i', (1, 2, 3))
+ b = self.array('h', a)
+ assert list(b) == [1, 2, 3]
+
def test_value_range(self):
import sys
values = (-129, 128, -128, 127, 0, 255, -1, 256,
More information about the pypy-commit
mailing list