[pypy-commit] pypy default: support adding a range list to an int list to get an int list
cfbolz
noreply at buildbot.pypy.org
Wed Oct 9 13:55:40 CEST 2013
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r67233:e47f03fa8558
Date: 2013-10-09 12:14 +0200
http://bitbucket.org/pypy/pypy/changeset/e47f03fa8558/
Log: support adding a range list to an int list to get an int list
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
@@ -30,7 +30,7 @@
from rpython.rlib import debug, jit, rerased
from rpython.rlib.listsort import make_timsort_class
from rpython.rlib.objectmodel import (
- instantiate, newlist_hint, resizelist_hint, specialize)
+ instantiate, newlist_hint, resizelist_hint, specialize, import_from_mixin)
from rpython.tool.sourcetools import func_with_new_name
__all__ = ['W_ListObject', 'make_range_list', 'make_empty_list_with_size']
@@ -1170,7 +1170,6 @@
class AbstractUnwrappedStrategy(object):
- _mixin_ = True
def wrap(self, unwrapped):
raise NotImplementedError
@@ -1456,7 +1455,9 @@
self.unerase(w_list.lstorage).reverse()
-class ObjectListStrategy(AbstractUnwrappedStrategy, ListStrategy):
+class ObjectListStrategy(ListStrategy):
+ import_from_mixin(AbstractUnwrappedStrategy)
+
_none_value = None
_applevel_repr = "object"
@@ -1489,7 +1490,9 @@
return self.unerase(w_list.lstorage)
-class IntegerListStrategy(AbstractUnwrappedStrategy, ListStrategy):
+class IntegerListStrategy(ListStrategy):
+ import_from_mixin(AbstractUnwrappedStrategy)
+
_none_value = 0
_applevel_repr = "int"
@@ -1520,7 +1523,21 @@
return self.unerase(w_list.lstorage)
-class FloatListStrategy(AbstractUnwrappedStrategy, ListStrategy):
+ _base_extend_from_list = _extend_from_list
+
+ def _extend_from_list(self, w_list, w_other):
+ if w_other.strategy is self.space.fromcache(RangeListStrategy):
+ l = self.unerase(w_list.lstorage)
+ other = w_other.getitems_int()
+ assert other is not None
+ l += other
+ return
+ return self._base_extend_from_list(w_list, w_other)
+
+
+class FloatListStrategy(ListStrategy):
+ import_from_mixin(AbstractUnwrappedStrategy)
+
_none_value = 0.0
_applevel_repr = "float"
@@ -1548,7 +1565,9 @@
l.reverse()
-class StringListStrategy(AbstractUnwrappedStrategy, ListStrategy):
+class StringListStrategy(ListStrategy):
+ import_from_mixin(AbstractUnwrappedStrategy)
+
_none_value = None
_applevel_repr = "str"
@@ -1579,7 +1598,9 @@
return self.unerase(w_list.lstorage)
-class UnicodeListStrategy(AbstractUnwrappedStrategy, ListStrategy):
+class UnicodeListStrategy(ListStrategy):
+ import_from_mixin(AbstractUnwrappedStrategy)
+
_none_value = None
_applevel_repr = "unicode"
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
@@ -467,6 +467,12 @@
l4 = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3), self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
assert self.space.eq_w(l3, l4)
+ def test_add_of_range_and_int(self):
+ l1 = make_range_list(self.space, 0, 1, 100)
+ l2 = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
+ l3 = self.space.add(l2, l1)
+ assert l3.strategy is l2.strategy
+
def test_mul(self):
l1 = W_ListObject(self.space, [self.space.wrap(1), self.space.wrap(2), self.space.wrap(3)])
l2 = l1.mul(2)
More information about the pypy-commit
mailing list