Commits

Philip Jenvey  committed 081d947

have space.warn take wrapped messages (eases py3k branch's usage) and accept a
stacklevel, cleanup

  • Participants
  • Parent commits 2dab420

Comments (0)

Files changed (12)

File pypy/interpreter/baseobjspace.py

             )
         return fd
 
-    def warn(self, msg, w_warningcls):
-        self.appexec([self.wrap(msg), w_warningcls], """(msg, warningcls):
+    def warn(self, w_msg, w_warningcls, stacklevel=2):
+        self.appexec([w_msg, w_warningcls, self.wrap(stacklevel)],
+                     """(msg, warningcls, stacklevel):
             import _warnings
-            _warnings.warn(msg, warningcls, stacklevel=2)
+            _warnings.warn(msg, warningcls, stacklevel=stacklevel)
         """)
 
 

File pypy/interpreter/pyopcode.py

 
     @jit.unroll_safe
     def cmp_exc_match(self, w_1, w_2):
-        if self.space.is_true(self.space.isinstance(w_2, self.space.w_tuple)):
-            for w_t in self.space.fixedview(w_2):
-                if self.space.is_true(self.space.isinstance(w_t,
-                                                            self.space.w_str)):
-                    self.space.warn("catching of string exceptions is "
-                                    "deprecated",
-                                    self.space.w_DeprecationWarning)
-        elif self.space.is_true(self.space.isinstance(w_2, self.space.w_str)):
-            self.space.warn("catching of string exceptions is deprecated",
-                            self.space.w_DeprecationWarning)
-        return self.space.newbool(self.space.exception_match(w_1, w_2))
+        space = self.space
+        if space.is_true(space.isinstance(w_2, space.w_tuple)):
+            for w_t in space.fixedview(w_2):
+                if space.is_true(space.isinstance(w_t, space.w_str)):
+                    msg = "catching of string exceptions is deprecated"
+                    space.warn(space.wrap(msg), space.w_DeprecationWarning)
+        elif space.is_true(space.isinstance(w_2, space.w_str)):
+            msg = "catching of string exceptions is deprecated"
+            space.warn(space.wrap(msg), space.w_DeprecationWarning)
+        return space.newbool(space.exception_match(w_1, w_2))
 
     def COMPARE_OP(self, testnum, next_instr):
         w_2 = self.popvalue()

File pypy/module/__builtin__/interp_classobj.py

                 return
             elif name == "__del__":
                 if self.lookup(space, name) is None:
-                    msg = ("a __del__ method added to an existing class "
-                           "will not be called")
-                    space.warn(msg, space.w_RuntimeWarning)
+                    msg = ("a __del__ method added to an existing class will "
+                           "not be called")
+                    space.warn(space.wrap(msg), space.w_RuntimeWarning)
         space.setitem(self.w_dict, w_attr, w_value)
 
     def descr_delattr(self, space, w_attr):
                 cache = space.fromcache(Cache)
                 if (not isinstance(self, cache.cls_with_del)
                     and self.getdictvalue(space, '__del__') is None):
-                    msg = ("a __del__ method added to an instance "
-                           "with no __del__ in the class will not be called")
-                    space.warn(msg, space.w_RuntimeWarning)
+                    msg = ("a __del__ method added to an instance with no "
+                           "__del__ in the class will not be called")
+                    space.warn(space.wrap(msg), space.w_RuntimeWarning)
         if w_meth is not None:
             space.call_function(w_meth, w_name, w_value)
         else:
             else:
                 w_as_str = self.descr_str(space)
             if space.len_w(w_format_spec) > 0:
-                space.warn(
-                    ("object.__format__ with a non-empty format string is "
-                        "deprecated"),
-                    space.w_PendingDeprecationWarning
-                )
+                msg = ("object.__format__ with a non-empty format string is "
+                       "deprecated")
+                space.warn(space.wrap(msg), space.w_PendingDeprecationWarning)
             return space.format(w_as_str, w_format_spec)
 
     def descr_len(self, space):

File pypy/module/_io/interp_bufferedio.py

         raise NotImplementedError
 
     def _deprecated_max_buffer_size(self, space):
-        space.warn("max_buffer_size is deprecated",
+        space.warn(space.wrap("max_buffer_size is deprecated"),
                    space.w_DeprecationWarning)
 
     def read_w(self, space, w_size=None):

File pypy/module/cpyext/import_.py

 
 @cpython_api([CONST_STRING], PyObject)
 def PyImport_ImportModuleNoBlock(space, name):
-    space.warn('PyImport_ImportModuleNoBlock() is not non-blocking',
-               space.w_RuntimeWarning)
+    space.warn(
+        space.wrap('PyImport_ImportModuleNoBlock() is not non-blocking'),
+        space.w_RuntimeWarning)
     return PyImport_Import(space, space.wrap(rffi.charp2str(name)))
 
 @cpython_api([PyObject], PyObject)

File pypy/module/exceptions/interp_exceptions.py

         if self.w_message is None:
             raise OperationError(space.w_AttributeError,
                                  space.wrap("message was deleted"))
-        space.warn("BaseException.message has been deprecated as of Python 2.6",
-                   space.w_DeprecationWarning)
+        msg = "BaseException.message has been deprecated as of Python 2.6"
+        space.warn(space.wrap(msg), space.w_DeprecationWarning)
         return self.w_message
 
     def descr_message_set(self, space, w_new):

File pypy/module/imp/importing.py

                     "Parent module '%s' not loaded, "
                     "cannot perform relative import" % ctxt_package))
             else:
-                space.warn("Parent module '%s' not found "
-                           "while handling absolute import" % ctxt_package,
-                           space.w_RuntimeWarning)
+                msg = ("Parent module '%s' not found while handling absolute "
+                       "import" % ctxt_package)
+                space.warn(space.wrap(msg), space.w_RuntimeWarning)
 
         rel_modulename = ctxt_package[:dot_position]
         rel_level = rel_modulename.count('.') + 1
                 if modtype in (PY_SOURCE, PY_COMPILED):
                     return FindInfo(PKG_DIRECTORY, filepart, None)
                 else:
-                    msg = "Not importing directory " +\
-                            "'%s' missing __init__.py" % (filepart,)
-                    space.warn(msg, space.w_ImportWarning)
+                    msg = ("Not importing directory '%s' missing __init__.py" %
+                           (filepart,))
+                    space.warn(space.wrap(msg), space.w_ImportWarning)
             modtype, suffix, filemode = find_modtype(space, filepart)
             try:
                 if modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION):

File pypy/module/struct/formatiterator.py

         def _maybe_float(self, w_obj):
             space = self.space
             if space.is_true(space.isinstance(w_obj, space.w_float)):
-                space.warn("struct: integer argument expected, got float",
-                           space.w_DeprecationWarning)
+                msg = "struct: integer argument expected, got float"
             else:
-                space.warn("integer argument expected, got non-integer",
-                           space.w_DeprecationWarning)
+                msg = "integer argument expected, got non-integer"
+            space.warn(space.wrap(msg), space.w_DeprecationWarning)
             return space.int(w_obj)   # wrapped float -> wrapped int or long
 
     else:

File pypy/objspace/std/complexobject.py

         return W_ComplexObject(rr, ir)
 
     def divmod(self, space, other):
-        space.warn(
-            "complex divmod(), // and % are deprecated",
-            space.w_DeprecationWarning
-        )
+        space.warn(space.wrap("complex divmod(), // and % are deprecated"),
+                   space.w_DeprecationWarning)
         w_div = self.div(other)
         div = math.floor(w_div.realval)
         w_mod = self.sub(

File pypy/objspace/std/objecttype.py

         msg = "format_spec must be a string"
         raise OperationError(space.w_TypeError, space.wrap(msg))
     if space.len_w(w_format_spec) > 0:
-        space.warn(
-            ("object.__format__ with a non-empty format string is "
-                "deprecated"),
-            space.w_PendingDeprecationWarning
-        )
+        msg = "object.__format__ with a non-empty format string is deprecated"
+        space.warn(space.wrap(msg), space.w_PendingDeprecationWarning)
     return space.format(w_as_str, w_format_spec)
 
 def descr___subclasshook__(space, __args__):

File pypy/objspace/std/typeobject.py

             msg = "can't set attributes on type object '%s'"
             raise operationerrfmt(space.w_TypeError, msg, w_self.name)
         if name == "__del__" and name not in w_self.dict_w:
-            msg = "a __del__ method added to an existing type will not be called"
-            space.warn(msg, space.w_RuntimeWarning)
+            msg = ("a __del__ method added to an existing type will not be "
+                   "called")
+            space.warn(space.wrap(msg), space.w_RuntimeWarning)
         if space.config.objspace.std.withtypeversion:
             version_tag = w_self.version_tag()
             if version_tag is not None:

File pypy/objspace/std/unicodeobject.py

         w_uni2 = uni_from_str(space, w_str)
     except OperationError, e:
         if e.match(space, space.w_UnicodeDecodeError):
-            if inverse:
-                msg = "Unicode unequal comparison failed to convert both "  \
-                      "arguments to Unicode - interpreting them as being unequal"
-            else :
-                msg = "Unicode equal comparison failed to convert both "    \
-                      "arguments to Unicode - interpreting them as being unequal"
-            space.warn(msg, space.w_UnicodeWarning)
+            msg = ("Unicode %s comparison failed to convert both arguments to "
+                   "Unicode - interpreting them as being unequal" %
+                   "unequal" if inverse else "equal")
+            space.warn(space.wrap(msg), space.w_UnicodeWarning)
             return space.newbool(inverse)
         raise
     result = space.eq(w_uni, w_uni2)