[pypy-commit] pypy remove-remaining-smm: Use oefmt.

Manuel Jacob noreply at buildbot.pypy.org
Mon Feb 24 20:48:33 CET 2014


Author: Manuel Jacob
Branch: remove-remaining-smm
Changeset: r69359:a9197ed339ea
Date: 2014-02-24 20:47 +0100
http://bitbucket.org/pypy/pypy/changeset/a9197ed339ea/

Log:	Use oefmt.

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
@@ -1,6 +1,6 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.baseobjspace import W_Root
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import oefmt
 from pypy.interpreter.function import Function, StaticMethod
 from pypy.interpreter.typedef import weakref_descr, GetSetProperty,\
      descr_get_dict
@@ -526,10 +526,9 @@
     def get_subclasses(w_self):
         space = w_self.space
         if not space.config.translation.rweakref:
-            msg = ("this feature requires weakrefs, "
-                   "which are not available in this build of PyPy")
-            raise OperationError(space.w_RuntimeError,
-                                 space.wrap(msg))
+            raise oefmt(space.w_RuntimeError,
+                        "this feature requires weakrefs, "
+                        "which are not available in this build of PyPy")
         subclasses_w = []
         for ref in w_self.weak_subclasses:
             w_ob = ref()
@@ -577,8 +576,7 @@
             w_descr = space.lookup(w_newobject, '__init__')
             w_result = space.get_and_call_args(w_descr, w_newobject, __args__)
             if not space.is_w(w_result, space.w_None):
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("__init__() should return None"))
+                raise oefmt(space.w_TypeError, "__init__() should return None")
         return w_newobject
 
     def descr_repr(self, space):
@@ -639,7 +637,7 @@
     # this is in its own function because we want the special case 'type(x)'
     # above to be seen by the jit.
     if w_bases is None or w_dict is None:
-        raise OperationError(space.w_TypeError, space.wrap("type() takes 1 or 3 arguments"))
+        raise oefmt(space.w_TypeError, "type() takes 1 or 3 arguments")
 
     bases_w = space.fixedview(w_bases)
 
@@ -653,11 +651,10 @@
         if space.is_true(space.issubtype(w_typ, w_winner)):
             w_winner = w_typ
             continue
-        raise OperationError(space.w_TypeError,
-                             space.wrap("metaclass conflict: "
-                                        "the metaclass of a derived class "
-                                        "must be a (non-strict) subclass "
-                                        "of the metaclasses of all its bases"))
+        raise oefmt(space.w_TypeError,
+                    "metaclass conflict: the metaclass of a derived class must"
+                    " be a (non-strict) subclass of the metaclasses of all its"
+                    " bases")
 
     if not space.is_w(w_winner, w_typetype):
         newfunc = space.getattr(w_winner, space.wrap('__new__'))
@@ -685,11 +682,9 @@
 
 # ____________________________________________________________
 
-def _check(space, w_type, w_msg=None):
+def _check(space, w_type, msg="descriptor is for 'type'"):
     if not isinstance(w_type, W_TypeObject):
-        if w_msg is None:
-            w_msg = space.wrap("descriptor is for 'type'")
-        raise OperationError(space.w_TypeError, w_msg)
+        raise oefmt(space.w_TypeError, msg)
     return w_type
 
 
@@ -709,7 +704,7 @@
 
 def descr_mro(space, w_type):
     """Return a type's method resolution order."""
-    w_type = _check(space, w_type, space.wrap("expected type"))
+    w_type = _check(space, w_type, "expected type")
     return space.newlist(w_type.compute_default_mro())
 
 def descr_get__bases__(space, w_type):
@@ -741,9 +736,8 @@
     for w_newbase in newbases_w:
         if isinstance(w_newbase, W_TypeObject):
             if w_type in w_newbase.compute_default_mro():
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("a __bases__ item causes"
-                                                " an inheritance cycle"))
+                raise oefmt(space.w_TypeError,
+                            "a __bases__ item causes an inheritance cycle")
 
     w_oldbestbase = check_and_find_best_base(space, w_type.bases_w)
     w_newbestbase = check_and_find_best_base(space, newbases_w)
@@ -833,8 +827,7 @@
         w_result = w_type.getdictvalue(space, "__abstractmethods__")
         if w_result is not None:
             return w_result
-    raise OperationError(space.w_AttributeError,
-                         space.wrap("__abstractmethods__"))
+    raise oefmt(space.w_AttributeError, "__abstractmethods__")
 
 def descr_set___abstractmethods__(space, w_type, w_new):
     w_type = _check(space, w_type)
@@ -844,8 +837,7 @@
 def descr_del___abstractmethods__(space, w_type):
     w_type = _check(space, w_type)
     if not w_type.deldictvalue(space, "__abstractmethods__"):
-        raise OperationError(space.w_AttributeError,
-                             space.wrap("__abstractmethods__"))
+        raise oefmt(space.w_AttributeError, "__abstractmethods__")
     w_type.set_abstract(False)
 
 def descr___subclasses__(space, w_type):
@@ -949,9 +941,8 @@
     """
     w_bestbase = find_best_base(space, bases_w)
     if w_bestbase is None:
-        raise OperationError(space.w_TypeError,
-                             space.wrap("a new-style class can't have "
-                                        "only classic bases"))
+        raise oefmt(space.w_TypeError,
+                    "a new-style class can't have only classic bases")
     if not w_bestbase.instancetypedef.acceptable_as_base_class:
         raise oefmt(space.w_TypeError,
                     "type '%N' is not an acceptable base class", w_bestbase)
@@ -962,9 +953,8 @@
         if isinstance(w_base, W_TypeObject):
             w_layout = w_base.w_same_layout_as or w_base
             if not issublayout(w_bestlayout, w_layout):
-                raise OperationError(space.w_TypeError,
-                                     space.wrap("instance layout conflicts in "
-                                                "multiple inheritance"))
+                raise oefmt(space.w_TypeError,
+                            "instance layout conflicts in multiple inheritance")
     return w_bestbase
 
 def copy_flags_from_bases(w_self, w_bestbase):
@@ -998,15 +988,13 @@
             slot_name = space.str_w(w_slot_name)
             if slot_name == '__dict__':
                 if wantdict or w_self.hasdict:
-                    raise OperationError(space.w_TypeError,
-                            space.wrap("__dict__ slot disallowed: "
-                                       "we already got one"))
+                    raise oefmt(space.w_TypeError,
+                                "__dict__ slot disallowed: we already got one")
                 wantdict = True
             elif slot_name == '__weakref__':
                 if wantweakref or w_self.weakrefable:
-                    raise OperationError(space.w_TypeError,
-                            space.wrap("__weakref__ slot disallowed: "
-                                       "we already got one"))
+                    raise oefmt(space.w_TypeError,
+                                "__weakref__ slot disallowed: we already got one")
                 wantweakref = True
             else:
                 create_slot(w_self, slot_name)
@@ -1021,8 +1009,7 @@
 def create_slot(w_self, slot_name):
     space = w_self.space
     if not valid_slot_name(slot_name):
-        raise OperationError(space.w_TypeError,
-                             space.wrap('__slots__ must be identifiers'))
+        raise oefmt(space.w_TypeError, "__slots__ must be identifiers")
     # create member
     slot_name = mangle(slot_name, w_self.name)
     if slot_name not in w_self.dict_w:
@@ -1122,8 +1109,7 @@
     # the elements in the mro seem to be (old- or new-style) classes.
     for w_class in mro_w:
         if not space.abstract_isclass_w(w_class):
-            raise OperationError(space.w_TypeError,
-                                 space.wrap("mro() returned a non-class"))
+            raise oefmt(space.w_TypeError, "mro() returned a non-class")
     return mro_w
 
 def is_mro_purely_of_types(mro_w):
@@ -1208,5 +1194,5 @@
     cycle.append(candidate)
     cycle.reverse()
     names = [cls.getname(space) for cls in cycle]
-    raise OperationError(space.w_TypeError,
-        space.wrap("cycle among base classes: " + ' < '.join(names)))
+    raise oefmt(space.w_TypeError,
+                "cycle among base classes: " + ' < '.join(names))


More information about the pypy-commit mailing list