[pypy-commit] pypy py3k: update to the new warn API

pjenvey noreply at buildbot.pypy.org
Tue Feb 19 23:50:16 CET 2013


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r61482:e23b1d81372f
Date: 2013-02-19 14:30 -0800
http://bitbucket.org/pypy/pypy/changeset/e23b1d81372f/

Log:	update to the new warn API

diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -105,7 +105,8 @@
         return space.wrap(len(data))
 
     def _complain_about_max_buffer_size(self, space):
-        space.warn("max_buffer_size is deprecated", space.w_DeprecationWarning)
+        space.warn(space.wrap("max_buffer_size is deprecated"),
+                   space.w_DeprecationWarning)
 
 W_BufferedIOBase.typedef = TypeDef(
     '_BufferedIOBase', W_IOBase.typedef,
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -249,14 +249,9 @@
     def _dealloc_warn_w(self, space, w_source):
         if self.fd >= 0 and self.closefd:
             try:
-                r = space.unicode_w(space.repr(w_source))
-                # TODO: space.warn is currently typed to str
-                #space.warn(u"unclosed file %s" % r, space.w_ResourceWarning)
-                msg = u"unclosed file %s" % r
-                space.appexec([space.wrap(msg), space.w_ResourceWarning],
-                              """(msg, warningcls):
-                import _warnings
-                _warnings.warn(msg, warningcls, stacklevel=2)""")
+                msg = (u"unclosed file %s" %
+                       space.unicode_w(space.repr(w_source)))
+                space.warn(space.wrap(msg), space.w_ResourceWarning)
             except OperationError as e:
                 # Spurious errors can appear at shutdown
                 if e.match(space, space.w_Warning):
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -575,8 +575,8 @@
         self.fromstring(space.bufferstr_w(w_s))
 
     def array_fromstring__Array_ANY(space, self, w_s):
-        space.warn("fromstring() is deprecated. Use frombytes() instead.",
-                   self.space.w_DeprecationWarning)
+        msg = "fromstring() is deprecated. Use frombytes() instead."
+        space.warn(space.wrap(msg), self.space.w_DeprecationWarning)
         self.fromstring(space.str_w(w_s))
 
     def array_tobytes__Array(space, self):
@@ -586,8 +586,8 @@
         return self.space.wrapbytes(s)
 
     def array_tostring__Array(space, self):
-        space.warn("tostring() is deprecated. Use tobytes() instead.",
-                   space.w_DeprecationWarning)
+        msg = "tostring() is deprecated. Use tobytes() instead."
+        space.warn(space.wrap(msg), space.w_DeprecationWarning)
         return array_tobytes__Array(space, self)
 
     def array_fromfile__Array_ANY_ANY(space, self, w_f, w_n):
diff --git a/pypy/module/rctime/interp_time.py b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -444,7 +444,7 @@
             else:
                 raise OperationError(space.w_ValueError,
                                      space.wrap("year out of range"))
-            space.warn("Century info guessed for a 2-digit year.",
+            space.warn(space.wrap("Century info guessed for a 2-digit year."),
                        space.w_DeprecationWarning)
 
     # tm_wday does not need checking of its upper-bound since taking "%
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -972,7 +972,8 @@
 
 def str__String(space, w_str):
     if space.sys.get_flag('bytes_warning'):
-        space.warn("str() on a bytes instance", space.w_BytesWarning)
+        space.warn(space.wrap("str() on a bytes instance"),
+                   space.w_BytesWarning)
     return repr__String(space, w_str)
 
 def ord__String(space, w_str):


More information about the pypy-commit mailing list