[pypy-commit] pypy default: have space.warn take wrapped messages (eases py3k branch's usage) and accept a
pjenvey
noreply at buildbot.pypy.org
Tue Feb 19 22:18:05 CET 2013
Author: Philip Jenvey <pjenvey at underboss.org>
Branch:
Changeset: r61469:081d9478f7b9
Date: 2013-02-19 13:17 -0800
http://bitbucket.org/pypy/pypy/changeset/081d9478f7b9/
Log: have space.warn take wrapped messages (eases py3k branch's usage)
and accept a stacklevel, cleanup
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1494,10 +1494,11 @@
)
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)
""")
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -776,17 +776,16 @@
@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()
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -154,9 +154,9 @@
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):
@@ -395,9 +395,9 @@
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:
@@ -454,11 +454,9 @@
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):
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
@@ -76,7 +76,7 @@
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):
diff --git a/pypy/module/cpyext/import_.py b/pypy/module/cpyext/import_.py
--- a/pypy/module/cpyext/import_.py
+++ b/pypy/module/cpyext/import_.py
@@ -46,8 +46,9 @@
@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)
diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -176,8 +176,8 @@
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):
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -174,9 +174,9 @@
"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
@@ -533,9 +533,9 @@
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):
diff --git a/pypy/module/struct/formatiterator.py b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -84,11 +84,10 @@
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:
diff --git a/pypy/objspace/std/complexobject.py b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -80,10 +80,8 @@
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(
diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -126,11 +126,8 @@
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__):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -295,8 +295,9 @@
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:
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
@@ -119,13 +119,10 @@
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)
More information about the pypy-commit
mailing list