Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r67234:b1f42572695e
Date: 2013-10-09 12:21 +0200
http://bitbucket.org/pypy/pypy/changeset/b1f42572695e/
Log: also support intlist[a:b:c] = rangelist (useful!)
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
@@ -1328,7 +1328,6 @@
def setslice(self, w_list, start, step, slicelength, w_other):
assert slicelength >= 0
- items = self.unerase(w_list.lstorage)
if self is self.space.fromcache(ObjectListStrategy):
w_other = w_other._temporarily_as_objects()
@@ -1340,6 +1339,7 @@
w_list.setslice(start, step, slicelength, w_other_as_object)
return
+ items = self.unerase(w_list.lstorage)
oldsize = len(items)
len2 = w_other.length()
if step == 1: # Support list resizing for non-extended slices
@@ -1535,6 +1535,15 @@
return self._base_extend_from_list(w_list, w_other)
+ _base_setslice = setslice
+
+ def setslice(self, w_list, start, step, slicelength, w_other):
+ if w_other.strategy is self.space.fromcache(RangeListStrategy):
+ storage = self.erase(w_other.getitems_int())
+ w_other = W_ListObject.from_storage_and_strategy(
+ self.space, storage, self)
+ return self._base_setslice(w_list, start, step, slicelength, w_other)
+
class FloatListStrategy(ListStrategy):
import_from_mixin(AbstractUnwrappedStrategy)
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
@@ -225,6 +225,15 @@
l.setslice(0, 1, 2, W_ListObject(space, [w('a'), w(2), w(3)]))
assert isinstance(l.strategy, ObjectListStrategy)
+ def test_setslice_int_range(self):
+ space = self.space
+ w = space.wrap
+ l = W_ListObject(space, [w(1), w(2), w(3)])
+ assert isinstance(l.strategy, IntegerListStrategy)
+ l.setslice(0, 1, 2, make_range_list(space, 5, 1, 4))
+ assert isinstance(l.strategy, IntegerListStrategy)
+
+
def test_setslice_List(self):
space = self.space
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit