[pypy-commit] pypy unicode-strategies: implement listview_unicode for sets
antocuni
noreply at buildbot.pypy.org
Fri Oct 26 21:45:36 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: unicode-strategies
Changeset: r58478:53359e7fb6fc
Date: 2012-10-26 21:38 +0200
http://bitbucket.org/pypy/pypy/changeset/53359e7fb6fc/
Log: implement listview_unicode for sets
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
@@ -471,8 +471,8 @@
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):
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -93,6 +93,10 @@
""" 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)
@@ -202,6 +206,9 @@
def listview_str(self, w_set):
return None
+ def listview_unicode(self, w_set):
+ return None
+
def listview_int(self, w_set):
return None
@@ -728,8 +735,8 @@
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
diff --git a/pypy/objspace/std/test/test_setstrategies.py b/pypy/objspace/std/test/test_setstrategies.py
--- a/pypy/objspace/std/test/test_setstrategies.py
+++ b/pypy/objspace/std/test/test_setstrategies.py
@@ -141,3 +141,14 @@
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"]
More information about the pypy-commit
mailing list