[pypy-commit] pypy py3.5: A more proper fix than 7d75f981d293: introduce and use the unwrap_spec

arigo pypy.commits at gmail.com
Fri Dec 16 05:19:19 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r89091:98017da1387f
Date: 2016-12-16 11:18 +0100
http://bitbucket.org/pypy/pypy/changeset/98017da1387f/

Log:	A more proper fix than 7d75f981d293: introduce and use the
	unwrap_spec 'text_or_None' (doesn't break randomly other things for
	now)

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1567,7 +1567,9 @@
         return self.buffer_w(w_obj, flags).as_str()
 
     def str_or_None_w(self, w_obj):
-        # FIXME: XXX for now, inconsistent with str_w()
+        return None if self.is_none(w_obj) else self.str_w(w_obj)
+
+    def text_or_None_w(self, w_obj):
         return None if self.is_none(w_obj) else self.identifier_w(w_obj)
 
     def str_w(self, w_obj):
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -156,6 +156,9 @@
     def visit_str_or_None(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
+    def visit_text_or_None(self, el, app_sig):
+        self.checked_space_method(el, app_sig)
+
     def visit_str0(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
@@ -296,6 +299,9 @@
     def visit_str_or_None(self, typ):
         self.run_args.append("space.str_or_None_w(%s)" % (self.scopenext(),))
 
+    def visit_text_or_None(self, typ):
+        self.run_args.append("space.text_or_None_w(%s)" % (self.scopenext(),))
+
     def visit_str0(self, typ):
         self.run_args.append("space.str0_w(%s)" % (self.scopenext(),))
 
@@ -455,6 +461,9 @@
     def visit_str_or_None(self, typ):
         self.unwrap.append("space.str_or_None_w(%s)" % (self.nextarg(),))
 
+    def visit_text_or_None(self, typ):
+        self.unwrap.append("space.text_or_None_w(%s)" % (self.nextarg(),))
+
     def visit_str0(self, typ):
         self.unwrap.append("space.str0_w(%s)" % (self.nextarg(),))
 
diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -206,7 +206,7 @@
         # we ignore w_type and always return a bytearray
         return new_bytearray(space, space.w_bytearray, data)
 
-    @unwrap_spec(encoding='str_or_None', errors='str_or_None')
+    @unwrap_spec(encoding='text_or_None', errors='text_or_None')
     def descr_init(self, space, w_source=None, encoding=None, errors=None):
         assert isinstance(self, W_BytearrayObject)
         data = [c for c in newbytesdata_w(space, w_source, encoding, errors)]
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -526,7 +526,7 @@
         return space.newlist_bytes(lst)
 
     @staticmethod
-    @unwrap_spec(encoding='str_or_None', errors='str_or_None')
+    @unwrap_spec(encoding='text_or_None', errors='text_or_None')
     def descr_new(space, w_stringtype, w_source=None, encoding=None,
                   errors=None):
         if (w_source and space.is_w(w_stringtype, space.w_bytes)


More information about the pypy-commit mailing list