Author: Armin Rigo <ar...@tunes.org>
Branch: py3.5-newtext
Changeset: r89205:f7ab12c69fc9
Date: 2016-12-20 15:39 +0100
http://bitbucket.org/pypy/pypy/changeset/f7ab12c69fc9/

Log:    fix dict tests

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -139,6 +139,7 @@
     # i.e. surrogates are accepted and not treated specially at all.
     # If there happen to be two 3-bytes encoding a pair of surrogates,
     # you still get two surrogate unicode characters in the result.
+    assert isinstance(string, str)
     result, consumed = runicode.str_decode_utf_8(
         string, len(string), "strict",
         final=True, errorhandler=decode_error_handler(space),
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -42,9 +42,9 @@
     def buffer_w(self, space, flags):
         return StringBuffer("foobar")
 
-    def str_w(self, space):
+    def text_w(self, space):
         return NonConstant("foobar")
-    identifier_w = bytes_w = str_w
+    identifier_w = bytes_w = text_w
 
     def unicode_w(self, space):
         return NonConstant(u"foobar")
@@ -118,7 +118,7 @@
 # ____________________________________________________________
 
 
-BUILTIN_TYPES = ['int', 'str', 'float', 'tuple', 'list', 'dict', 'bytes',
+BUILTIN_TYPES = ['int', 'float', 'tuple', 'list', 'dict', 'bytes',
                  'unicode', 'complex', 'slice', 'bool', 'text', 'object',
                  'set', 'frozenset', 'bytearray', 'memoryview']
 
diff --git a/pypy/objspace/std/dictmultiobject.py 
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -1016,7 +1016,7 @@
 
     def is_correct_type(self, w_obj):
         space = self.space
-        return space.is_w(space.type(w_obj), space.w_str)
+        return space.is_w(space.type(w_obj), space.w_bytes)
 
     def get_empty_storage(self):
         res = {}
@@ -1167,7 +1167,7 @@
         space = self.space
         # XXX there are many more types
         return (space.is_w(w_lookup_type, space.w_NoneType) or
-                space.is_w(w_lookup_type, space.w_str) or
+                space.is_w(w_lookup_type, space.w_bytes) or
                 space.is_w(w_lookup_type, space.w_unicode)
                 )
 
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py 
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -1131,6 +1131,8 @@
         return l
     def newlist_bytes(self, l):
         return l
+    def newlist_text(self, l):
+        return l
     def newlist_unicode(self, l):
         return l
     DictObjectCls = W_DictObject
@@ -1140,23 +1142,20 @@
         if isinstance(w_obj, FakeUnicode):
             return unicode
         return type(w_obj)
-    w_str = str
     w_unicode = unicode
+    w_bytes = str
 
-    def str_w(self, string):
-        if isinstance(string, unicode):
-            return string.encode('utf-8')
-        assert isinstance(string, str)
-        return string
-    bytes_w = str_w
+    def text_w(self, u):
+        assert isinstance(u, unicode)
+        return u.encode('utf-8')
 
     def bytes_w(self, string):
         assert isinstance(string, str)
         return string
 
-    def unicode_w(self, string):
-        assert isinstance(string, unicode)
-        return string
+    def unicode_w(self, u):
+        assert isinstance(u, unicode)
+        return u
 
     def int_w(self, integer, allow_conversion=True):
         assert isinstance(integer, int)
@@ -1166,7 +1165,14 @@
         if isinstance(obj, str):
             return obj.decode('ascii')
         return obj
-    newtext = newbytes = wrap
+
+    def newunicode(self, u):
+        assert isinstance(u, unicode)
+        return u
+
+    def newtext(self, string):
+        assert isinstance(string, str)
+        return string.decode('utf-8')
 
     def newbytes(self, obj):
         return obj
@@ -1212,7 +1218,7 @@
     StringObjectCls = FakeString
     UnicodeObjectCls = FakeUnicode
     w_dict = W_DictObject
-    w_text = str
+    w_text = unicode
     iter = iter
     fixedview = list
     listview  = list
@@ -1355,7 +1361,7 @@
     def test_devolve(self):
         impl = self.impl
         for x in xrange(100):
-            impl.setitem(self.fakespace.str_w(str(x)), x)
+            impl.setitem(self.fakespace.text_w(unicode(x)), x)
             impl.setitem(x, x)
         assert type(impl.get_strategy()) is ObjectDictStrategy
 
@@ -1419,10 +1425,10 @@
         assert self.fakespace.view_as_kwargs(self.impl) == (["fish", "fish2"], 
[1000, 2000])
 
     def test_setitem_str(self):
-        self.impl.setitem_str(self.fakespace.str_w(self.string), 1000)
+        self.impl.setitem_str(self.fakespace.text_w(self.string), 1000)
         assert self.impl.length() == 1
         assert self.impl.getitem(self.string) == 1000
-        assert self.impl.getitem_str(self.string) == 1000
+        assert self.impl.getitem_str(str(self.string)) == 1000
         self.check_not_devolved()
 
 class TestBytesDictImplementation(BaseTestRDictImplementation):
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -326,8 +326,8 @@
     def descr_repr(self, space):
         chars = self._value
         size = len(chars)
-        s = _repr_function(chars, size, "strict")
-        return space.newtext(s)
+        u = _repr_function(chars, size, "strict")
+        return space.newunicode(u)
 
     def descr_str(self, space):
         if space.is_w(space.type(self), space.w_unicode):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to