[pypy-commit] pypy py3k: replace StringSetStrategy with UnicodeSetStrategy; earlier, we but bytes into sets but we got out strings

antocuni noreply at buildbot.pypy.org
Tue Sep 25 17:15:26 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57584:f12b530717ff
Date: 2012-09-25 17:14 +0200
http://bitbucket.org/pypy/pypy/changeset/f12b530717ff/

Log:	replace StringSetStrategy with UnicodeSetStrategy; earlier, we but
	bytes into sets but we got out strings

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
@@ -12,7 +12,7 @@
 from pypy.interpreter.generator import GeneratorIterator
 from pypy.objspace.std.listobject import W_ListObject
 from pypy.objspace.std.intobject import W_IntObject
-from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.unicodeobject import W_UnicodeObject
 
 class W_BaseSetObject(W_Object):
     typedef = None
@@ -291,8 +291,8 @@
     def add(self, w_set, w_key):
         if type(w_key) is W_IntObject:
             strategy = self.space.fromcache(IntegerSetStrategy)
-        elif type(w_key) is W_StringObject:
-            strategy = self.space.fromcache(StringSetStrategy)
+        elif type(w_key) is W_UnicodeObject:
+            strategy = self.space.fromcache(UnicodeSetStrategy)
         else:
             strategy = self.space.fromcache(ObjectSetStrategy)
         w_set.strategy = strategy
@@ -670,8 +670,8 @@
                             self.space.wrap('pop from an empty set'))
         return self.wrap(result[0])
 
-class StringSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
-    erase, unerase = rerased.new_erasing_pair("string")
+class UnicodeSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
+    erase, unerase = rerased.new_erasing_pair("unicode")
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
 
@@ -685,7 +685,7 @@
         return self.unerase(w_set.sstorage).keys()
 
     def is_correct_type(self, w_key):
-        return type(w_key) is W_StringObject
+        return type(w_key) is W_UnicodeObject
 
     def may_contain_equal_elements(self, strategy):
         if strategy is self.space.fromcache(IntegerSetStrategy):
@@ -701,7 +701,7 @@
         return self.space.wrap(item)
 
     def iter(self, w_set):
-        return StringIteratorImplementation(self.space, self, w_set)
+        return UnicodeIteratorImplementation(self.space, self, w_set)
 
 class IntegerSetStrategy(AbstractUnwrappedSetStrategy, SetStrategy):
     erase, unerase = rerased.new_erasing_pair("integer")
@@ -722,7 +722,7 @@
         return type(w_key) is W_IntObject
 
     def may_contain_equal_elements(self, strategy):
-        if strategy is self.space.fromcache(StringSetStrategy):
+        if strategy is self.space.fromcache(UnicodeSetStrategy):
             return False
         if strategy is self.space.fromcache(EmptySetStrategy):
             return False
@@ -830,7 +830,7 @@
         return None
 
 
-class StringIteratorImplementation(IteratorImplementation):
+class UnicodeIteratorImplementation(IteratorImplementation):
     def __init__(self, space, strategy, w_set):
         IteratorImplementation.__init__(self, space, strategy, w_set)
         d = strategy.unerase(w_set.sstorage)
@@ -916,7 +916,7 @@
 
     stringlist = space.listview_str(w_iterable)
     if stringlist is not None:
-        strategy = space.fromcache(StringSetStrategy)
+        strategy = space.fromcache(UnicodeSetStrategy)
         w_set.strategy = strategy
         w_set.sstorage = strategy.get_storage_from_unwrapped_list(stringlist)
         return
@@ -949,10 +949,10 @@
 
     # check for strings
     for w_item in iterable_w:
-        if type(w_item) is not W_StringObject:
+        if type(w_item) is not W_UnicodeObject:
             break
     else:
-        w_set.strategy = space.fromcache(StringSetStrategy)
+        w_set.strategy = space.fromcache(UnicodeSetStrategy)
         w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
         return
 
@@ -1397,6 +1397,7 @@
             if not s:
                 return '%s()' % (s.__class__.__name__,)
             listrepr = repr([x for x in s])
+            print('XXX', listrepr)
             if type(s) is set:
                 return '{%s}' % (listrepr[1:-1],)
             else:
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -57,7 +57,7 @@
         assert self.space.str_w(self.space.repr(s)) == 'set()'
         # check that the second time we don't get 'set(...)'
         assert self.space.str_w(self.space.repr(s)) == 'set()'
-        
+
     def test_intersection_order(self):
         # theses tests make sure that intersection is done in the correct order
         # (smallest first)
@@ -87,7 +87,7 @@
         assert space.is_true(self.space.eq(result, W_SetObject(space, self.space.wrap(""))))
 
     def test_create_set_from_list(self):
-        from pypy.objspace.std.setobject import ObjectSetStrategy, StringSetStrategy
+        from pypy.objspace.std.setobject import ObjectSetStrategy, UnicodeSetStrategy
         from pypy.objspace.std.floatobject import W_FloatObject
         from pypy.objspace.std.model import W_Object
 
@@ -106,7 +106,7 @@
         w_list = W_ListObject(self.space, [w("1"), w("2"), w("3")])
         w_set = W_SetObject(self.space)
         _initialize_set(self.space, w_set, w_list)
-        assert w_set.strategy is self.space.fromcache(StringSetStrategy)
+        assert w_set.strategy is self.space.fromcache(UnicodeSetStrategy)
         assert w_set.strategy.unerase(w_set.sstorage) == {"1":None, "2":None, "3":None}
 
         w_list = W_ListObject(self.space, [w("1"), w(2), w("3")])
@@ -341,6 +341,10 @@
         d = a.union()
         assert d == a
 
+    def test_bytes_items(self):
+        s = set([b'hello'])
+        assert s.pop() == b'hello'
+
     def test_compare(self):
         assert set('abc') != 'abc'
         raises(TypeError, "set('abc') < 42")
@@ -457,7 +461,7 @@
         assert therepr.endswith("})")
         inner = set(therepr[11:-2].split(", "))
         assert inner == set(["1", "2", "3", "frozenset(...)"])
-        
+
     def test_keyerror_has_key(self):
         s = set()
         try:


More information about the pypy-commit mailing list