Author: Brian Kearns <[email protected]>
Branch: 
Changeset: r62741:7799ba9b4dc3
Date: 2013-03-25 07:38 -0400
http://bitbucket.org/pypy/pypy/changeset/7799ba9b4dc3/

Log:    use UnicodeSetStrategy when creating from an iterable, test

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
@@ -1053,6 +1053,15 @@
         w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
         return
 
+    # check for unicode
+    for w_item in iterable_w:
+        if type(w_item) is not W_UnicodeObject:
+            break
+    else:
+        w_set.strategy = space.fromcache(UnicodeSetStrategy)
+        w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
+        return
+
     w_set.strategy = space.fromcache(ObjectSetStrategy)
     w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
 
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
@@ -84,7 +84,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, 
StringSetStrategy, UnicodeSetStrategy
         from pypy.objspace.std.floatobject import W_FloatObject
         from pypy.objspace.std.model import W_Object
 
@@ -106,6 +106,12 @@
         assert w_set.strategy is self.space.fromcache(StringSetStrategy)
         assert w_set.strategy.unerase(w_set.sstorage) == {"1":None, "2":None, 
"3":None}
 
+        w_list = self.space.iter(W_ListObject(self.space, [w(u"1"), w(u"2"), 
w(u"3")]))
+        w_set = W_SetObject(self.space)
+        _initialize_set(self.space, w_set, w_list)
+        assert w_set.strategy is self.space.fromcache(UnicodeSetStrategy)
+        assert w_set.strategy.unerase(w_set.sstorage) == {u"1":None, 
u"2":None, u"3":None}
+
         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)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to