Commits

Philip Jenvey committed b9437d4

fix cell/mapdict

Comments (0)

Files changed (4)

pypy/objspace/std/celldict.py

 
     def setitem(self, w_dict, w_key, w_value):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_str):
+        if space.is_w(space.type(w_key), space.w_unicode):
             self.setitem_str(w_dict, space.str_w(w_key), w_value)
         else:
             self.switch_to_object_strategy(w_dict)
 
     def setdefault(self, w_dict, w_key, w_default):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_str):
+        if space.is_w(space.type(w_key), space.w_unicode):
             key = space.str_w(w_key)
             w_result = self.getitem_str(w_dict, key)
             if w_result is not None:
     def delitem(self, w_dict, w_key):
         space = self.space
         w_key_type = space.type(w_key)
-        if space.is_w(w_key_type, space.w_str):
+        if space.is_w(w_key_type, space.w_unicode):
             key = space.str_w(w_key)
             dict_w = self.unerase(w_dict.dstorage)
             try:
     def getitem(self, w_dict, w_key):
         space = self.space
         w_lookup_type = space.type(w_key)
-        if space.is_w(w_lookup_type, space.w_str):
+        if space.is_w(w_lookup_type, space.w_unicode):
             return self.getitem_str(w_dict, space.str_w(w_key))
 
         elif _never_equal_to_string(space, w_lookup_type):

pypy/objspace/std/mapdict.py

     def getitem(self, w_dict, w_key):
         space = self.space
         w_lookup_type = space.type(w_key)
-        if space.is_w(w_lookup_type, space.w_str):
+        if space.is_w(w_lookup_type, space.w_unicode):
             return self.getitem_str(w_dict, space.str_w(w_key))
         elif _never_equal_to_string(space, w_lookup_type):
             return None
 
     def setitem(self, w_dict, w_key, w_value):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_str):
+        if space.is_w(space.type(w_key), space.w_unicode):
             self.setitem_str(w_dict, self.space.str_w(w_key), w_value)
         else:
             self.switch_to_object_strategy(w_dict)
 
     def setdefault(self, w_dict, w_key, w_default):
         space = self.space
-        if space.is_w(space.type(w_key), space.w_str):
+        if space.is_w(space.type(w_key), space.w_unicode):
             key = space.str_w(w_key)
             w_result = self.getitem_str(w_dict, key)
             if w_result is not None:
         space = self.space
         w_key_type = space.type(w_key)
         w_obj = self.unerase(w_dict.dstorage)
-        if space.is_w(w_key_type, space.w_str):
+        if space.is_w(w_key_type, space.w_unicode):
             key = self.space.str_w(w_key)
             flag = w_obj.deldictvalue(space, key)
             if not flag:

pypy/objspace/std/test/test_celldict.py

 from pypy.objspace.std.dictmultiobject import W_DictMultiObject
 from pypy.objspace.std.test.test_dictmultiobject import (
     BaseTestRDictImplementation, BaseTestDevolvedDictImplementation, FakeSpace,
-    FakeString)
+    FakeUnicode)
 
 space = FakeSpace()
 
 class TestCellDict(object):
-    FakeString = FakeString
+    FakeString = FakeUnicode
 
     def test_basic_property_cells(self):
         strategy = ModuleDictStrategy(space)
 
         v1 = strategy.version
         x = object()
-        d.setitem("a", x)
+        d.setitem(u"a", x)
         v2 = strategy.version
         assert v1 is not v2
-        d.setitem("a", x)
+        d.setitem(u"a", x)
         v3 = strategy.version
         assert v2 is v3
 
         assert "ModuleDictStrategy" in __pypy__.internal_repr(obj)
 
     def test_check_module_uses_module_dict(self):
-        py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
+        #py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
         m = type(__builtins__)("abc")
         self.impl_used(m.__dict__)
 
         assert x == ("a", 3)
 
     def test_degenerate(self):
-        py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
+        #py3k_skip("ModuleDictStrategy is immediately turned into ObjectDictStrategy because we use unicode keys now")
         import __pypy__
 
         d = self.d

pypy/objspace/std/test/test_dictmultiobject.py

 
 class BaseTestRDictImplementation:
     FakeString = FakeUnicode
-    allows__str = False
+    allows__str = False # XXX: this is maybe not necessary, just add tests to unicode to ensure we're allowing utf-8?
 
     def setup_method(self,method):
         self.fakespace = FakeSpace()
         key = self.FakeString(self.string)
         x = impl.setdefault(key, 1)
         assert x == 1
-        if on_pypy:
+        if on_pypy and self.FakeString is FakeString:
             assert key.hash_count == 1
         x = impl.setdefault(key, 2)
         assert x == 1
-        if on_pypy:
+        if on_pypy and self.FakeString is FakeString:
             assert key.hash_count == 2
 
     def test_fallback_evil_key(self):