Author: Antonio Cuni <[email protected]>
Branch: fast_cffi_list_init
Changeset: r67275:90ba1db68c0a
Date: 2013-10-10 11:21 +0200
http://bitbucket.org/pypy/pypy/changeset/90ba1db68c0a/

Log:    introduce space.listview_float

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
@@ -292,6 +292,11 @@
         """Return the items in the list as unwrapped ints. If the list does not
         use the list strategy, return None."""
         return self.strategy.getitems_int(self)
+
+    def getitems_float(self):
+        """Return the items in the list as unwrapped floats. If the list does 
not
+        use the list strategy, return None."""
+        return self.strategy.getitems_float(self)
     # ___________________________________________________
 
     def mul(self, times):
@@ -757,6 +762,9 @@
     def getitems_int(self, w_list):
         return None
 
+    def getitems_float(self, w_list):
+        return None
+
     def getstorage_copy(self, w_list):
         raise NotImplementedError
 
@@ -1575,6 +1583,9 @@
         if reverse:
             l.reverse()
 
+    def getitems_float(self, w_list):
+        return self.unerase(w_list.lstorage)
+
 
 class StringListStrategy(ListStrategy):
     import_from_mixin(AbstractUnwrappedStrategy)
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
@@ -472,6 +472,15 @@
             return w_obj.getitems_int()
         return None
 
+    def listview_float(self, w_obj):
+        if type(w_obj) is W_ListObject:
+            return w_obj.getitems_float()
+        # dict and set don't have FloatStrategy, so we can just ignore them
+        # for now
+        if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj):
+            return w_obj.getitems_float()
+        return None
+
     def view_as_kwargs(self, w_dict):
         if type(w_dict) is W_DictMultiObject:
             return w_dict.view_as_kwargs()
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
@@ -645,6 +645,11 @@
         w_l = W_ListObject(space, [space.wrap(1), space.wrap(2), 
space.wrap(3)])
         assert self.space.listview_int(w_l) == [1, 2, 3]
 
+    def test_listview_float_list(self):
+        space = self.space
+        w_l = W_ListObject(space, [space.wrap(1.1), space.wrap(2.2), 
space.wrap(3.3)])
+        assert self.space.listview_float(w_l) == [1.1, 2.2, 3.3]
+
 
 class TestW_ListStrategiesDisabled:
     spaceconfig = {"objspace.std.withliststrategies": False}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to