Commits

Antonio Cuni committed 53359e7

implement listview_unicode for sets

Comments (0)

Files changed (3)

pypy/objspace/std/objspace.py

             return w_obj.getitems_unicode()
         if type(w_obj) is W_DictMultiObject:
             return w_obj.listview_unicode()
-        ## if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
-        ##     return w_obj.listview_unicode()
+        if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
+            return w_obj.listview_unicode()
         ## if isinstance(w_obj, W_UnicodeObject):
         ##     return w_obj.listview_unicode()
         if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj):

pypy/objspace/std/setobject.py

         """ If this is a string set return its contents as a list of uwnrapped strings. Otherwise return None. """
         return self.strategy.listview_str(self)
 
+    def listview_unicode(self):
+        """ If this is a unicode set return its contents as a list of uwnrapped unicodes. Otherwise return None. """
+        return self.strategy.listview_unicode(self)
+
     def listview_int(self):
         """ If this is an int set return its contents as a list of uwnrapped ints. Otherwise return None. """
         return self.strategy.listview_int(self)
     def listview_str(self, w_set):
         return None
 
+    def listview_unicode(self, w_set):
+        return None
+
     def listview_int(self, w_set):
         return None
 
     def get_empty_dict(self):
         return {}
 
-    ## def listview_unicode(self, w_set):
-    ##     return self.unerase(w_set.sstorage).keys()
+    def listview_unicode(self, w_set):
+        return self.unerase(w_set.sstorage).keys()
 
     def is_correct_type(self, w_key):
         return type(w_key) is W_UnicodeObject

pypy/objspace/std/test/test_setstrategies.py

         assert isinstance(it, UnicodeIteratorImplementation)
         assert space.unwrap(it.next()) == u"a"
         assert space.unwrap(it.next()) == u"b"
+
+    def test_listview(self):
+        space = self.space
+        s = W_SetObject(space, self.wrapped([1,2]))
+        assert sorted(space.listview_int(s)) == [1, 2]
+        #
+        s = W_SetObject(space, self.wrapped(["a", "b"]))
+        assert sorted(space.listview_str(s)) == ["a", "b"]
+        #
+        s = W_SetObject(space, self.wrapped([u"a", u"b"]))
+        assert sorted(space.listview_unicode(s)) == [u"a", u"b"]