Author: Lukas Diekmann <[email protected]>
Branch: list-strategies
Changeset: r47446:71cbd6ccc1b1
Date: 2011-03-01 16:36 +0100
http://bitbucket.org/pypy/pypy/changeset/71cbd6ccc1b1/
Log: (l.diekmann, cfbolz): store list as unwrapped data
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -55,6 +55,7 @@
def __init__(w_self, space, wrappeditems):
assert isinstance(wrappeditems, list)
+ w_self.space = space
w_self.strategy = get_strategy_from_list_objects(space, wrappeditems)
w_self.strategy.init_from_list_w(w_self, wrappeditems)
@@ -67,14 +68,15 @@
items = [space.unwrap(w_item) for w_item in w_list.getitems()]
return list(items)
- def switch_to_object_strategy(self, items_w):
- self.strategy = ObjectListStrategy()
- self.strategy.init_from_list_w(self, items_w)
+ def switch_to_object_strategy(self):
+ list_w = self.getitems()
+ self.strategy = ObjectListStrategy(self.space)
+ self.strategy.init_from_list_w(self, list_w)
- def check_empty_strategy(self, items_w):
- if len(items_w) == 0:
- self.strategy = EmptyListStrategy()
- self.strategy.init_from_list_w(self, items_w)
+ def check_empty_strategy(self):
+ if self.length() == 0:
+ self.strategy = EmptyListStrategy(self.space)
+ self.strategy.init_from_list_w(self, [])
# ___________________________________________________
@@ -176,6 +178,7 @@
raise NotImplementedError
class EmptyListStrategy(ListStrategy):
+
def init_from_list_w(self, w_list, list_w):
assert len(list_w) == 0
w_list.storage = cast_to_void_star(None)
@@ -187,13 +190,13 @@
raise IndexError
def getslice(self, w_list, start, stop, step, length):
- return W_ListObject([])
+ return W_ListObject(self.space, [])
def getitems(self, w_list):
return []
def append(self, w_list, w_item):
- w_list.__init__([w_item])
+ w_list.__init__(self.space, [w_item])
def inplace_mul(self, w_list, times):
return
@@ -211,7 +214,7 @@
raise IndexError
def setslice(self, w_list, start, step, slicelength, sequence_w):
- w_list.__init__(sequence_w)
+ w_list.__init__(self.space, sequence_w)
def insert(self, w_list, index, w_item):
assert index == 0
@@ -242,6 +245,9 @@
def list_is_correct_type(self, w_list):
raise NotImplementedError("abstract base class")
+ def init_from_list_w(self, w_list, list_w):
+ l = [self.unwrap(w_item) for w_item in list_w]
+ w_list.storage = self.cast_to_void_star(l)
def length(self, w_list):
return len(self.cast_from_void_star(w_list.storage))
@@ -253,17 +259,20 @@
raise
def getitems(self, w_list):
- return self.cast_from_void_star(w_list.storage)
+ return [self.wrap(item) for item in
self.cast_from_void_star(w_list.storage)]
def getslice(self, w_list, start, stop, step, length):
if step == 1:
- return
W_ListObject(self.cast_from_void_star(w_list.storage)[start:stop])
+ # XXX ineffecient cause items are wrapped and unwrapped again
+ # later: W_ListObject constructor for unwrapped items
+ l = w_list.getitems()
+ return W_ListObject(self.space, l[start:stop])
else:
subitems_w = [None] * length
for i in range(length):
subitems_w[i] = w_list.getitem(start)
start += step
- return W_ListObject(subitems_w)
+ return W_ListObject(self.space, subitems_w)
def append(self, w_list, w_item):
@@ -271,44 +280,52 @@
self.cast_from_void_star(w_list.storage).append(self.unwrap(w_item))
return
- w_list.switch_to_object_strategy(w_list.getitems())
+ w_list.switch_to_object_strategy()
w_list.append(w_item)
def insert(self, w_list, index, w_item):
- list_w = self.cast_from_void_star(w_list.storage)
+ l = self.cast_from_void_star(w_list.storage)
if self.is_correct_type(w_item):
- list_w.insert(index, w_item)
+ l.insert(index, self.unwrap(w_item))
return
- w_list.switch_to_object_strategy(list_w)
+ w_list.switch_to_object_strategy()
w_list.insert(index, w_item)
def extend(self, w_list, w_other):
- list_w = self.cast_from_void_star(w_list.storage)
+ l = self.cast_from_void_star(w_list.storage)
if self.list_is_correct_type(w_other):
- list_w += w_other.getitems() # or
self.cast_from_void_star(w_other.storage) ?
+ l += self.cast_from_void_star(w_other.storage)
return
- w_list.switch_to_object_strategy(list_w)
+ #XXX unnecessary copy if w_other is ObjectList
+ list_w = w_other.getitems()
+ w_other = W_ListObject(self.space, list_w)
+ w_other.switch_to_object_strategy()
+
+ w_list.switch_to_object_strategy()
w_list.extend(w_other)
def setitem(self, w_list, index, w_item):
- list_w = self.cast_from_void_star(w_list.storage)
+ l = self.cast_from_void_star(w_list.storage)
if self.is_correct_type(w_item):
- list_w[index] = w_item
+ l[index] = self.unwrap(w_item)
return
- w_list.switch_to_object_strategy(list_w)
+ w_list.switch_to_object_strategy()
w_list.setitem(index, w_item)
def setslice(self, w_list, start, step, slicelength, sequence_w):
+ #XXX inefficient
assert slicelength >= 0
items = self.cast_from_void_star(w_list.storage)
- if not self.list_is_correct_type(W_ListObject(sequence_w)):
- w_list.switch_to_object_strategy(items)
+ if (type(self) is not ObjectListStrategy and
+ not self.list_is_correct_type(W_ListObject(self.space,
sequence_w)) and
+ len(sequence_w) != 0):
+ w_list.switch_to_object_strategy()
w_list.setslice(start, step, slicelength, sequence_w)
return
@@ -343,22 +360,22 @@
i = len2 - 1
start += i*step
while i >= 0:
- items[start] = sequence_w[i]
+ items[start] = self.unwrap(sequence_w[i])
start -= step
i -= 1
return
else:
# Make a shallow copy to more easily handle the reversal case
+ # XXX why is this needed ???
sequence_w = list(sequence_w)
for i in range(len2):
items[start] = self.unwrap(sequence_w[i])
start += step
-
def deleteitem(self, w_list, index):
- list_w = self.cast_from_void_star(w_list.storage)
- del list_w[index]
- w_list.check_empty_strategy(list_w)
+ l = self.cast_from_void_star(w_list.storage)
+ del l[index]
+ w_list.check_empty_strategy()
def deleteslice(self, w_list, start, step, slicelength):
items = self.cast_from_void_star(w_list.storage)
@@ -392,18 +409,18 @@
assert start >= 0 # annotator hint
del items[start:]
- w_list.check_empty_strategy(items)
+ w_list.check_empty_strategy()
def pop(self, w_list, index):
- list_w = self.cast_from_void_star(w_list.storage)
- item_w = self.wrap(list_w.pop(index))
+ l = self.cast_from_void_star(w_list.storage)
+ w_item = self.wrap(l.pop(index))
- w_list.check_empty_strategy(list_w)
- return item_w
+ w_list.check_empty_strategy()
+ return w_item
def inplace_mul(self, w_list, times):
- list_w = self.cast_from_void_star(w_list.storage)
- list_w *= times
+ l = self.cast_from_void_star(w_list.storage)
+ l *= times
def reverse(self, w_list):
self.cast_from_void_star(w_list.storage).reverse()
@@ -422,7 +439,7 @@
return True
def list_is_correct_type(self, w_list):
- return True
+ return ObjectListStrategy is type(w_list.strategy)
def init_from_list_w(self, w_list, list_w):
w_list.storage = cast_to_void_star(list_w, "object")
@@ -438,14 +455,14 @@
def cast_from_void_star(self, storage):
return cast_from_void_star(storage, "integer")
+ def cast_to_void_star(self, l):
+ return cast_to_void_star(l, "integer")
+
def is_correct_type(self, w_obj):
return is_W_IntObject(w_obj)
def list_is_correct_type(self, w_list):
- return type(self) == type(w_list.strategy)
-
- def init_from_list_w(self, w_list, list_w):
- w_list.storage = cast_to_void_star(list_w, "integer")
+ return IntegerListStrategy is type(w_list.strategy)
class StringListStrategy(AbstractUnwrappedStrategy):
@@ -458,14 +475,14 @@
def cast_from_void_star(self, storage):
return cast_from_void_star(storage, "string")
+ def cast_to_void_star(self, l):
+ return cast_to_void_star(l, "string")
+
def is_correct_type(self, w_obj):
return is_W_StringObject(w_obj)
def list_is_correct_type(self, w_list):
- return type(self) == type(w_list.strategy)
-
- def init_from_list_w(self, w_list, list_w):
- w_list.storage = cast_to_void_star(list_w, "string")
+ return StringListStrategy is type(w_list.strategy)
# _______________________________________________________
@@ -484,8 +501,7 @@
# This is commented out to avoid assigning a new RPython list to
# 'wrappeditems', which defeats the W_FastSeqIterObject optimization.
#
- items_w = w_list.getitems()
- del items_w[:]
+ w_list.__init__(space, [])
if w_iterable is not None:
w_iterator = space.iter(w_iterable)
while True:
@@ -546,7 +562,7 @@
return iterobject.W_FastListIterObject(w_list, w_list.getitems())
def add__List_List(space, w_list1, w_list2):
- return W_ListObject(w_list1.getitems() + w_list2.getitems())
+ return W_ListObject(space, w_list1.getitems() + w_list2.getitems())
def inplace_add__List_ANY(space, w_list1, w_iterable2):
@@ -564,7 +580,7 @@
if e.match(space, space.w_TypeError):
raise FailedToImplement
raise
- return W_ListObject(w_list.getitems() * times)
+ return W_ListObject(space, w_list.getitems() * times)
def mul__List_ANY(space, w_list, w_times):
return mul_list_times(space, w_list, w_times)
@@ -709,8 +725,8 @@
return space.w_None
def list_extend__List_ANY(space, w_list, w_any):
- w_other = W_ListObject(space.listview(w_any))
- w_list.extend(w_other)
+ w_other = W_ListObject(space, space.listview(w_any))
+ w_list.extend(w_other)
return space.w_None
# note that the default value will come back wrapped!!!
@@ -836,7 +852,7 @@
# by comparison functions can't affect the slice of memory we're
# sorting (allowing mutations during sorting is an IndexError or
# core-dump factory, since wrappeditems may change).
- w_list.__init__([])
+ w_list.__init__(space, [])
# wrap each item in a KeyContainer if needed
if has_key:
@@ -869,7 +885,7 @@
mucked = w_list.length() > 0
# put the items back into the list
- w_list.__init__(sorter.list)
+ w_list.__init__(space, sorter.list)
if mucked:
raise OperationError(space.w_ValueError,
diff --git a/pypy/objspace/std/listtype.py b/pypy/objspace/std/listtype.py
--- a/pypy/objspace/std/listtype.py
+++ b/pypy/objspace/std/listtype.py
@@ -43,7 +43,7 @@
def descr__new__(space, w_listtype, __args__):
from pypy.objspace.std.listobject import W_ListObject
w_obj = space.allocate_instance(W_ListObject, w_listtype)
- W_ListObject.__init__(w_obj, [])
+ W_ListObject.__init__(w_obj, space, [])
return w_obj
# ____________________________________________________________
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -274,7 +274,7 @@
return wraptuple(self, list_w)
def newlist(self, list_w):
- return W_ListObject(list_w)
+ return W_ListObject(self, list_w)
def newdict(self, module=False, instance=False, classofinstance=None,
from_strdict_shared=None, strdict=False):
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -9,25 +9,25 @@
def test_is_true(self):
w = self.space.wrap
- w_list = W_ListObject([])
+ w_list = W_ListObject(self.space, [])
assert self.space.is_true(w_list) == False
- w_list = W_ListObject([w(5)])
+ w_list = W_ListObject(self.space, [w(5)])
assert self.space.is_true(w_list) == True
- w_list = W_ListObject([w(5), w(3)])
+ w_list = W_ListObject(self.space, [w(5), w(3)])
assert self.space.is_true(w_list) == True
def test_len(self):
w = self.space.wrap
- w_list = W_ListObject([])
+ w_list = W_ListObject(self.space, [])
assert self.space.eq_w(self.space.len(w_list), w(0))
- w_list = W_ListObject([w(5)])
+ w_list = W_ListObject(self.space, [w(5)])
assert self.space.eq_w(self.space.len(w_list), w(1))
- w_list = W_ListObject([w(5), w(3), w(99)]*111)
+ w_list = W_ListObject(self.space, [w(5), w(3), w(99)]*111)
assert self.space.eq_w(self.space.len(w_list), w(333))
def test_getitem(self):
w = self.space.wrap
- w_list = W_ListObject([w(5), w(3)])
+ w_list = W_ListObject(self.space, [w(5), w(3)])
assert self.space.eq_w(self.space.getitem(w_list, w(0)), w(5))
assert self.space.eq_w(self.space.getitem(w_list, w(1)), w(3))
assert self.space.eq_w(self.space.getitem(w_list, w(-2)), w(5))
@@ -42,7 +42,7 @@
def test_random_getitem(self):
w = self.space.wrap
s = list('qedx387tn3uixhvt 7fh387fymh3dh238 dwd-wq.dwq9')
- w_list = W_ListObject(map(w, s))
+ w_list = W_ListObject(self.space, map(w, s))
keys = range(-len(s)-5, len(s)+5)
choices = keys + [None]*12
stepchoices = [None, None, None, 1, 1, -1, -1, 2, -2,
@@ -65,7 +65,7 @@
def test_iter(self):
w = self.space.wrap
- w_list = W_ListObject([w(5), w(3), w(99)])
+ w_list = W_ListObject(self.space, [w(5), w(3), w(99)])
w_iter = self.space.iter(w_list)
assert self.space.eq_w(self.space.next(w_iter), w(5))
assert self.space.eq_w(self.space.next(w_iter), w(3))
@@ -75,7 +75,7 @@
def test_contains(self):
w = self.space.wrap
- w_list = W_ListObject([w(5), w(3), w(99)])
+ w_list = W_ListObject(self.space, [w(5), w(3), w(99)])
assert self.space.eq_w(self.space.contains(w_list, w(5)),
self.space.w_True)
assert self.space.eq_w(self.space.contains(w_list, w(99)),
@@ -90,7 +90,7 @@
def test1(testlist, start, stop, step, expected):
w_slice = self.space.newslice(w(start), w(stop), w(step))
- w_list = W_ListObject([w(i) for i in testlist])
+ w_list = W_ListObject(self.space, [w(i) for i in testlist])
w_result = self.space.getitem(w_list, w_slice)
assert self.space.unwrap(w_result) == expected
@@ -111,8 +111,8 @@
def test1(lhslist, start, stop, rhslist, expected):
w_slice = self.space.newslice(w(start), w(stop), w(1))
- w_lhslist = W_ListObject([w(i) for i in lhslist])
- w_rhslist = W_ListObject([w(i) for i in rhslist])
+ w_lhslist = W_ListObject(self.space, [w(i) for i in lhslist])
+ w_rhslist = W_ListObject(self.space, [w(i) for i in rhslist])
self.space.setitem(w_lhslist, w_slice, w_rhslist)
assert self.space.unwrap(w_lhslist) == expected
@@ -126,14 +126,14 @@
def test_add(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(-7)] * 111)
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(-7)] * 111)
assert self.space.eq_w(self.space.add(w_list1, w_list1),
- W_ListObject([w(5), w(3), w(99),
+ W_ListObject(self.space, [w(5), w(3), w(99),
w(5), w(3), w(99)]))
assert self.space.eq_w(self.space.add(w_list1, w_list2),
- W_ListObject([w(5), w(3), w(99)] +
+ W_ListObject(self.space, [w(5), w(3), w(99)] +
[w(-7)] * 111))
assert self.space.eq_w(self.space.add(w_list1, w_list0), w_list1)
assert self.space.eq_w(self.space.add(w_list0, w_list2), w_list2)
@@ -143,8 +143,8 @@
w = self.space.wrap
arg = w(2)
n = 3
- w_lis = W_ListObject([arg])
- w_lis3 = W_ListObject([arg]*n)
+ w_lis = W_ListObject(self.space, [arg])
+ w_lis3 = W_ListObject(self.space, [arg]*n)
w_res = self.space.mul(w_lis, w(n))
assert self.space.eq_w(w_lis3, w_res)
# commute
@@ -153,9 +153,9 @@
def test_setitem(self):
w = self.space.wrap
- w_list = W_ListObject([w(5), w(3)])
- w_exp1 = W_ListObject([w(5), w(7)])
- w_exp2 = W_ListObject([w(8), w(7)])
+ w_list = W_ListObject(self.space, [w(5), w(3)])
+ w_exp1 = W_ListObject(self.space, [w(5), w(7)])
+ w_exp2 = W_ListObject(self.space, [w(8), w(7)])
self.space.setitem(w_list, w(1), w(7))
assert self.space.eq_w(w_exp1, w_list)
self.space.setitem(w_list, w(-2), w(8))
@@ -168,7 +168,7 @@
def test_random_setitem_delitem(self):
w = self.space.wrap
s = range(39)
- w_list = W_ListObject(map(w, s))
+ w_list = W_ListObject(self.space, map(w, s))
expected = list(s)
keys = range(-len(s)-5, len(s)+5)
choices = keys + [None]*12
@@ -184,7 +184,7 @@
for key in keys:
if random.random() < 0.15:
random.shuffle(s)
- w_list = W_ListObject(map(w, s))
+ w_list = W_ListObject(self.space, map(w, s))
expected = list(s)
try:
value = expected[key]
@@ -220,10 +220,10 @@
def test_eq(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
assert self.space.eq_w(self.space.eq(w_list0, w_list1),
self.space.w_False)
@@ -238,10 +238,10 @@
def test_ne(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
assert self.space.eq_w(self.space.ne(w_list0, w_list1),
self.space.w_True)
@@ -256,11 +256,11 @@
def test_lt(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
- w_list4 = W_ListObject([w(5), w(3), w(9), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
+ w_list4 = W_ListObject(self.space, [w(5), w(3), w(9), w(-1)])
assert self.space.eq_w(self.space.lt(w_list0, w_list1),
self.space.w_True)
@@ -278,11 +278,11 @@
def test_ge(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
- w_list4 = W_ListObject([w(5), w(3), w(9), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
+ w_list4 = W_ListObject(self.space, [w(5), w(3), w(9), w(-1)])
assert self.space.eq_w(self.space.ge(w_list0, w_list1),
self.space.w_False)
@@ -300,11 +300,11 @@
def test_gt(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
- w_list4 = W_ListObject([w(5), w(3), w(9), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
+ w_list4 = W_ListObject(self.space, [w(5), w(3), w(9), w(-1)])
assert self.space.eq_w(self.space.gt(w_list0, w_list1),
self.space.w_False)
@@ -322,11 +322,11 @@
def test_le(self):
w = self.space.wrap
- w_list0 = W_ListObject([])
- w_list1 = W_ListObject([w(5), w(3), w(99)])
- w_list2 = W_ListObject([w(5), w(3), w(99)])
- w_list3 = W_ListObject([w(5), w(3), w(99), w(-1)])
- w_list4 = W_ListObject([w(5), w(3), w(9), w(-1)])
+ w_list0 = W_ListObject(self.space, [])
+ w_list1 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list2 = W_ListObject(self.space, [w(5), w(3), w(99)])
+ w_list3 = W_ListObject(self.space, [w(5), w(3), w(99), w(-1)])
+ w_list4 = W_ListObject(self.space, [w(5), w(3), w(9), w(-1)])
assert self.space.eq_w(self.space.le(w_list0, w_list1),
self.space.w_True)
diff --git a/pypy/objspace/std/test/test_liststrategies.py
b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -4,29 +4,29 @@
class TestW_ListStrategies(TestW_ListObject):
def test_check_strategy(self):
- assert isinstance(W_ListObject([]).strategy, EmptyListStrategy)
- assert
isinstance(W_ListObject([self.space.wrap(1),self.space.wrap('a')]).strategy,
ObjectListStrategy)
- assert
isinstance(W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)]).strategy,
IntegerListStrategy)
- assert isinstance(W_ListObject([self.space.wrap('a'),
self.space.wrap('b')]).strategy, StringListStrategy)
+ assert isinstance(W_ListObject(self.space, []).strategy,
EmptyListStrategy)
+ assert isinstance(W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap('a')]).strategy, ObjectListStrategy)
+ assert isinstance(W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)]).strategy,
IntegerListStrategy)
+ assert isinstance(W_ListObject(self.space, [self.space.wrap('a'),
self.space.wrap('b')]).strategy, StringListStrategy)
def test_empty_to_any(self):
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.append(self.space.wrap(1.))
assert isinstance(l.strategy, ObjectListStrategy)
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.append(self.space.wrap(1))
assert isinstance(l.strategy, IntegerListStrategy)
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.append(self.space.wrap('a'))
assert isinstance(l.strategy, StringListStrategy)
def test_int_to_any(self):
- l =
W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
+ l = W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.append(self.space.wrap(4))
assert isinstance(l.strategy, IntegerListStrategy)
@@ -34,7 +34,7 @@
assert isinstance(l.strategy, ObjectListStrategy)
def test_string_to_any(self):
- l =
W_ListObject([self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
+ l = W_ListObject(self.space,
[self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
assert isinstance(l.strategy, StringListStrategy)
l.append(self.space.wrap('d'))
assert isinstance(l.strategy, StringListStrategy)
@@ -43,7 +43,7 @@
def test_setitem(self):
# This should work if test_listobject.py passes
- l =
W_ListObject([self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
+ l = W_ListObject(self.space,
[self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
assert self.space.eq_w(l.getitem(0), self.space.wrap('a'))
l.setitem(0, self.space.wrap('d'))
assert self.space.eq_w(l.getitem(0), self.space.wrap('d'))
@@ -51,97 +51,97 @@
assert isinstance(l.strategy, StringListStrategy)
# IntStrategy to ObjectStrategy
- l =
W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
+ l = W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.setitem(0, self.space.wrap('d'))
assert isinstance(l.strategy, ObjectListStrategy)
# StringStrategy to ObjectStrategy
- l =
W_ListObject([self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
+ l = W_ListObject(self.space,
[self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
assert isinstance(l.strategy, StringListStrategy)
l.setitem(0, self.space.wrap(2))
assert isinstance(l.strategy, ObjectListStrategy)
def test_insert(self):
# no change
- l =
W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
+ l = W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.insert(3, self.space.wrap(4))
assert isinstance(l.strategy, IntegerListStrategy)
# StringStrategy
- l =
W_ListObject([self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
+ l = W_ListObject(self.space,
[self.space.wrap('a'),self.space.wrap('b'),self.space.wrap('c')])
assert isinstance(l.strategy, StringListStrategy)
l.insert(3, self.space.wrap(2))
assert isinstance(l.strategy, ObjectListStrategy)
# IntegerStrategy
- l =
W_ListObject([self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
+ l = W_ListObject(self.space,
[self.space.wrap(1),self.space.wrap(2),self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.insert(3, self.space.wrap('d'))
assert isinstance(l.strategy, ObjectListStrategy)
# EmptyStrategy
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.insert(0, self.space.wrap('a'))
assert isinstance(l.strategy, StringListStrategy)
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.insert(0, self.space.wrap(2))
assert isinstance(l.strategy, IntegerListStrategy)
def test_list_empty_after_delete(self):
- l = W_ListObject([self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.deleteitem(0)
assert isinstance(l.strategy, EmptyListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap(2)])
+ l = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2)])
assert isinstance(l.strategy, IntegerListStrategy)
l.deleteslice(0, 1, 2)
assert isinstance(l.strategy, EmptyListStrategy)
- l = W_ListObject([self.space.wrap(1)])
+ l = W_ListObject(self.space, [self.space.wrap(1)])
assert isinstance(l.strategy, IntegerListStrategy)
l.pop(-1)
assert isinstance(l.strategy, EmptyListStrategy)
def test_setslice(self):
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
l.setslice(0, 1, 2, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.setslice(0, 1, 2, [self.space.wrap(4), self.space.wrap(5),
self.space.wrap(6)])
assert isinstance(l.strategy, IntegerListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap('b'),
self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(1),
self.space.wrap('b'), self.space.wrap(3)])
assert isinstance(l.strategy, ObjectListStrategy)
l.setslice(0, 1, 2, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, ObjectListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
l.setslice(0, 1, 2, [self.space.wrap('a'), self.space.wrap('b'),
self.space.wrap('c')])
assert isinstance(l.strategy, ObjectListStrategy)
def test_extend(self):
- l = W_ListObject([])
+ l = W_ListObject(self.space, [])
assert isinstance(l.strategy, EmptyListStrategy)
- l.extend(W_ListObject([self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)]))
+ l.extend(W_ListObject(self.space, [self.space.wrap(1),
self.space.wrap(2), self.space.wrap(3)]))
assert isinstance(l.strategy, IntegerListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
- l.extend(W_ListObject([self.space.wrap('a'), self.space.wrap('b'),
self.space.wrap('c')]))
+ l.extend(W_ListObject(self.space, [self.space.wrap('a'),
self.space.wrap('b'), self.space.wrap('c')]))
assert isinstance(l.strategy, ObjectListStrategy)
- l = W_ListObject([self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
+ l = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2),
self.space.wrap(3)])
assert isinstance(l.strategy, IntegerListStrategy)
- l.extend(W_ListObject([self.space.wrap(4), self.space.wrap(5),
self.space.wrap(6)]))
+ l.extend(W_ListObject(self.space, [self.space.wrap(4),
self.space.wrap(5), self.space.wrap(6)]))
assert isinstance(l.strategy, IntegerListStrategy)
diff --git a/pypy/objspace/std/test/test_stringobject.py
b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -495,7 +495,7 @@
assert "".join([]) == ""
assert "-".join(['a', 'b']) == 'a-b'
text = 'text'
- assert "".join([text]) is text
+ assert "".join([text]) == text
raises(TypeError, ''.join, 1)
raises(TypeError, ''.join, [1])
raises(TypeError, ''.join, [[1]])
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit