[pypy-svn] pypy default: Display the name of the derived class in AttributeError messages

amauryfa commits-noreply at bitbucket.org
Fri Mar 11 18:21:00 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r42521:09ee6be1af7a
Date: 2011-03-11 17:00 +0100
http://bitbucket.org/pypy/pypy/changeset/09ee6be1af7a/

Log:	Display the name of the derived class in AttributeError messages

diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -429,8 +429,9 @@
         else:
             flag = self.data.field_masks[field]
         self.emit("if not w_self.initialization_state & %s:" % (flag,), 1)
-        self.emit("w_err = space.wrap(\"'%s' object has no attribute '%s'\")" %
-                  (name, field.name,), 2)
+        self.emit("typename = space.type(w_self).getname(space)", 2)
+        self.emit("w_err = space.wrap(\"'%%s' object has no attribute '%s'\" %% typename)" %
+                  (field.name,), 2)
         self.emit("raise OperationError(space.w_AttributeError, w_err)", 2)
         if field.seq:
             self.emit("if w_self.w_%s is None:" % (field.name,), 1)

diff --git a/pypy/interpreter/astcompiler/ast.py b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -3058,7 +3058,8 @@
 
 def Module_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Module' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3100,7 +3101,8 @@
 
 def Interactive_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Interactive' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3142,7 +3144,8 @@
 
 def Expression_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Expression' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
@@ -3176,7 +3179,8 @@
 
 def Suite_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Suite' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3218,7 +3222,8 @@
 
 def stmt_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("'stmt' object has no attribute 'lineno'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'lineno'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
@@ -3228,7 +3233,8 @@
 
 def stmt_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("'stmt' object has no attribute 'col_offset'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'col_offset'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
@@ -3246,7 +3252,8 @@
 
 def FunctionDef_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'FunctionDef' object has no attribute 'name'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'name'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
@@ -3256,7 +3263,8 @@
 
 def FunctionDef_get_args(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'FunctionDef' object has no attribute 'args'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'args'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.args)
 
@@ -3266,7 +3274,8 @@
 
 def FunctionDef_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'FunctionDef' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3283,7 +3292,8 @@
 
 def FunctionDef_get_decorator_list(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("'FunctionDef' object has no attribute 'decorator_list'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'decorator_list'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_decorator_list is None:
         if w_self.decorator_list is None:
@@ -3329,7 +3339,8 @@
 
 def ClassDef_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'ClassDef' object has no attribute 'name'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'name'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
@@ -3339,7 +3350,8 @@
 
 def ClassDef_get_bases(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'ClassDef' object has no attribute 'bases'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'bases'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_bases is None:
         if w_self.bases is None:
@@ -3356,7 +3368,8 @@
 
 def ClassDef_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'ClassDef' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3373,7 +3386,8 @@
 
 def ClassDef_get_decorator_list(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("'ClassDef' object has no attribute 'decorator_list'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'decorator_list'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_decorator_list is None:
         if w_self.decorator_list is None:
@@ -3420,7 +3434,8 @@
 
 def Return_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Return' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -3454,7 +3469,8 @@
 
 def Delete_get_targets(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Delete' object has no attribute 'targets'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'targets'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_targets is None:
         if w_self.targets is None:
@@ -3496,7 +3512,8 @@
 
 def Assign_get_targets(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Assign' object has no attribute 'targets'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'targets'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_targets is None:
         if w_self.targets is None:
@@ -3513,7 +3530,8 @@
 
 def Assign_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Assign' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -3549,7 +3567,8 @@
 
 def AugAssign_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'AugAssign' object has no attribute 'target'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'target'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
@@ -3559,7 +3578,8 @@
 
 def AugAssign_get_op(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'AugAssign' object has no attribute 'op'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'op'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return operator_to_class[w_self.op - 1]()
 
@@ -3570,7 +3590,8 @@
 
 def AugAssign_get_value(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'AugAssign' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -3606,7 +3627,8 @@
 
 def Print_get_dest(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Print' object has no attribute 'dest'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'dest'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.dest)
 
@@ -3616,7 +3638,8 @@
 
 def Print_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Print' object has no attribute 'values'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'values'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
@@ -3633,7 +3656,8 @@
 
 def Print_get_nl(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Print' object has no attribute 'nl'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'nl'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.nl)
 
@@ -3670,7 +3694,8 @@
 
 def For_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'For' object has no attribute 'target'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'target'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
@@ -3680,7 +3705,8 @@
 
 def For_get_iter(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'For' object has no attribute 'iter'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'iter'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.iter)
 
@@ -3690,7 +3716,8 @@
 
 def For_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'For' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3707,7 +3734,8 @@
 
 def For_get_orelse(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("'For' object has no attribute 'orelse'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'orelse'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
@@ -3753,7 +3781,8 @@
 
 def While_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'While' object has no attribute 'test'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'test'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
@@ -3763,7 +3792,8 @@
 
 def While_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'While' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3780,7 +3810,8 @@
 
 def While_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'While' object has no attribute 'orelse'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'orelse'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
@@ -3825,7 +3856,8 @@
 
 def If_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'If' object has no attribute 'test'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'test'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
@@ -3835,7 +3867,8 @@
 
 def If_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'If' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3852,7 +3885,8 @@
 
 def If_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'If' object has no attribute 'orelse'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'orelse'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
@@ -3897,7 +3931,8 @@
 
 def With_get_context_expr(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'With' object has no attribute 'context_expr'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'context_expr'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.context_expr)
 
@@ -3907,7 +3942,8 @@
 
 def With_get_optional_vars(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'With' object has no attribute 'optional_vars'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'optional_vars'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.optional_vars)
 
@@ -3917,7 +3953,8 @@
 
 def With_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'With' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -3961,7 +3998,8 @@
 
 def Raise_get_type(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Raise' object has no attribute 'type'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'type'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.type)
 
@@ -3971,7 +4009,8 @@
 
 def Raise_get_inst(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Raise' object has no attribute 'inst'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'inst'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.inst)
 
@@ -3981,7 +4020,8 @@
 
 def Raise_get_tback(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Raise' object has no attribute 'tback'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'tback'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.tback)
 
@@ -4017,7 +4057,8 @@
 
 def TryExcept_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'TryExcept' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -4034,7 +4075,8 @@
 
 def TryExcept_get_handlers(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'TryExcept' object has no attribute 'handlers'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'handlers'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_handlers is None:
         if w_self.handlers is None:
@@ -4051,7 +4093,8 @@
 
 def TryExcept_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'TryExcept' object has no attribute 'orelse'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'orelse'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
@@ -4097,7 +4140,8 @@
 
 def TryFinally_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'TryFinally' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -4114,7 +4158,8 @@
 
 def TryFinally_get_finalbody(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'TryFinally' object has no attribute 'finalbody'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'finalbody'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_finalbody is None:
         if w_self.finalbody is None:
@@ -4158,7 +4203,8 @@
 
 def Assert_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Assert' object has no attribute 'test'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'test'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
@@ -4168,7 +4214,8 @@
 
 def Assert_get_msg(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Assert' object has no attribute 'msg'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'msg'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.msg)
 
@@ -4203,7 +4250,8 @@
 
 def Import_get_names(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Import' object has no attribute 'names'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'names'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
@@ -4245,7 +4293,8 @@
 
 def ImportFrom_get_module(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'ImportFrom' object has no attribute 'module'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'module'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.module)
 
@@ -4258,7 +4307,8 @@
 
 def ImportFrom_get_names(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'ImportFrom' object has no attribute 'names'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'names'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
@@ -4275,7 +4325,8 @@
 
 def ImportFrom_get_level(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'ImportFrom' object has no attribute 'level'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'level'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.level)
 
@@ -4312,7 +4363,8 @@
 
 def Exec_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Exec' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
@@ -4322,7 +4374,8 @@
 
 def Exec_get_globals(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Exec' object has no attribute 'globals'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'globals'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.globals)
 
@@ -4332,7 +4385,8 @@
 
 def Exec_get_locals(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Exec' object has no attribute 'locals'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'locals'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.locals)
 
@@ -4368,7 +4422,8 @@
 
 def Global_get_names(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Global' object has no attribute 'names'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'names'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
@@ -4410,7 +4465,8 @@
 
 def Expr_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Expr' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -4495,7 +4551,8 @@
 
 def expr_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("'expr' object has no attribute 'lineno'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'lineno'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
@@ -4505,7 +4562,8 @@
 
 def expr_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("'expr' object has no attribute 'col_offset'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'col_offset'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
@@ -4523,7 +4581,8 @@
 
 def BoolOp_get_op(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'BoolOp' object has no attribute 'op'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'op'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return boolop_to_class[w_self.op - 1]()
 
@@ -4534,7 +4593,8 @@
 
 def BoolOp_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'BoolOp' object has no attribute 'values'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'values'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
@@ -4577,7 +4637,8 @@
 
 def BinOp_get_left(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'BinOp' object has no attribute 'left'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'left'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.left)
 
@@ -4587,7 +4648,8 @@
 
 def BinOp_get_op(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'BinOp' object has no attribute 'op'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'op'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return operator_to_class[w_self.op - 1]()
 
@@ -4598,7 +4660,8 @@
 
 def BinOp_get_right(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'BinOp' object has no attribute 'right'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'right'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.right)
 
@@ -4634,7 +4697,8 @@
 
 def UnaryOp_get_op(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'UnaryOp' object has no attribute 'op'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'op'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return unaryop_to_class[w_self.op - 1]()
 
@@ -4645,7 +4709,8 @@
 
 def UnaryOp_get_operand(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'UnaryOp' object has no attribute 'operand'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'operand'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.operand)
 
@@ -4680,7 +4745,8 @@
 
 def Lambda_get_args(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Lambda' object has no attribute 'args'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'args'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.args)
 
@@ -4690,7 +4756,8 @@
 
 def Lambda_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Lambda' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
@@ -4725,7 +4792,8 @@
 
 def IfExp_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'IfExp' object has no attribute 'test'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'test'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
@@ -4735,7 +4803,8 @@
 
 def IfExp_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'IfExp' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
@@ -4745,7 +4814,8 @@
 
 def IfExp_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'IfExp' object has no attribute 'orelse'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'orelse'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.orelse)
 
@@ -4781,7 +4851,8 @@
 
 def Dict_get_keys(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Dict' object has no attribute 'keys'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'keys'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_keys is None:
         if w_self.keys is None:
@@ -4798,7 +4869,8 @@
 
 def Dict_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Dict' object has no attribute 'values'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'values'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
@@ -4842,7 +4914,8 @@
 
 def Set_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Set' object has no attribute 'elts'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elts'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
@@ -4884,7 +4957,8 @@
 
 def ListComp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'ListComp' object has no attribute 'elt'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elt'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
@@ -4894,7 +4968,8 @@
 
 def ListComp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'ListComp' object has no attribute 'generators'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'generators'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
@@ -4937,7 +5012,8 @@
 
 def SetComp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'SetComp' object has no attribute 'elt'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elt'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
@@ -4947,7 +5023,8 @@
 
 def SetComp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'SetComp' object has no attribute 'generators'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'generators'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
@@ -4990,7 +5067,8 @@
 
 def DictComp_get_key(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'DictComp' object has no attribute 'key'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'key'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.key)
 
@@ -5000,7 +5078,8 @@
 
 def DictComp_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'DictComp' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -5010,7 +5089,8 @@
 
 def DictComp_get_generators(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'DictComp' object has no attribute 'generators'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'generators'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
@@ -5054,7 +5134,8 @@
 
 def GeneratorExp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'GeneratorExp' object has no attribute 'elt'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elt'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
@@ -5064,7 +5145,8 @@
 
 def GeneratorExp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'GeneratorExp' object has no attribute 'generators'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'generators'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
@@ -5107,7 +5189,8 @@
 
 def Yield_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Yield' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -5141,7 +5224,8 @@
 
 def Compare_get_left(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Compare' object has no attribute 'left'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'left'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.left)
 
@@ -5151,7 +5235,8 @@
 
 def Compare_get_ops(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Compare' object has no attribute 'ops'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ops'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_ops is None:
         if w_self.ops is None:
@@ -5168,7 +5253,8 @@
 
 def Compare_get_comparators(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Compare' object has no attribute 'comparators'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'comparators'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_comparators is None:
         if w_self.comparators is None:
@@ -5213,7 +5299,8 @@
 
 def Call_get_func(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Call' object has no attribute 'func'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'func'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.func)
 
@@ -5223,7 +5310,8 @@
 
 def Call_get_args(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Call' object has no attribute 'args'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'args'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_args is None:
         if w_self.args is None:
@@ -5240,7 +5328,8 @@
 
 def Call_get_keywords(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Call' object has no attribute 'keywords'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'keywords'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_keywords is None:
         if w_self.keywords is None:
@@ -5257,7 +5346,8 @@
 
 def Call_get_starargs(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("'Call' object has no attribute 'starargs'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'starargs'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.starargs)
 
@@ -5267,7 +5357,8 @@
 
 def Call_get_kwargs(space, w_self):
     if not w_self.initialization_state & 16:
-        w_err = space.wrap("'Call' object has no attribute 'kwargs'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'kwargs'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.kwargs)
 
@@ -5307,7 +5398,8 @@
 
 def Repr_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Repr' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -5341,7 +5433,8 @@
 
 def Num_get_n(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Num' object has no attribute 'n'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'n'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.n
 
@@ -5375,7 +5468,8 @@
 
 def Str_get_s(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Str' object has no attribute 's'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 's'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.s
 
@@ -5412,7 +5506,8 @@
 
 def Attribute_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Attribute' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -5422,7 +5517,8 @@
 
 def Attribute_get_attr(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Attribute' object has no attribute 'attr'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'attr'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.attr)
 
@@ -5432,7 +5528,8 @@
 
 def Attribute_get_ctx(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Attribute' object has no attribute 'ctx'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ctx'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
@@ -5469,7 +5566,8 @@
 
 def Subscript_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Subscript' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -5479,7 +5577,8 @@
 
 def Subscript_get_slice(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Subscript' object has no attribute 'slice'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'slice'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.slice)
 
@@ -5489,7 +5588,8 @@
 
 def Subscript_get_ctx(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Subscript' object has no attribute 'ctx'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ctx'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
@@ -5526,7 +5626,8 @@
 
 def Name_get_id(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Name' object has no attribute 'id'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'id'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.id)
 
@@ -5536,7 +5637,8 @@
 
 def Name_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Name' object has no attribute 'ctx'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ctx'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
@@ -5572,7 +5674,8 @@
 
 def List_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'List' object has no attribute 'elts'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elts'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
@@ -5589,7 +5692,8 @@
 
 def List_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'List' object has no attribute 'ctx'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ctx'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
@@ -5626,7 +5730,8 @@
 
 def Tuple_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Tuple' object has no attribute 'elts'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'elts'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
@@ -5643,7 +5748,8 @@
 
 def Tuple_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Tuple' object has no attribute 'ctx'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ctx'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
@@ -5680,7 +5786,8 @@
 
 def Const_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Const' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.value
 
@@ -5785,7 +5892,8 @@
 
 def Slice_get_lower(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Slice' object has no attribute 'lower'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'lower'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lower)
 
@@ -5795,7 +5903,8 @@
 
 def Slice_get_upper(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'Slice' object has no attribute 'upper'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'upper'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.upper)
 
@@ -5805,7 +5914,8 @@
 
 def Slice_get_step(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'Slice' object has no attribute 'step'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'step'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.step)
 
@@ -5841,7 +5951,8 @@
 
 def ExtSlice_get_dims(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'ExtSlice' object has no attribute 'dims'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'dims'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_dims is None:
         if w_self.dims is None:
@@ -5883,7 +5994,8 @@
 
 def Index_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'Index' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -6137,7 +6249,8 @@
 
 def comprehension_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'comprehension' object has no attribute 'target'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'target'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
@@ -6147,7 +6260,8 @@
 
 def comprehension_get_iter(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'comprehension' object has no attribute 'iter'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'iter'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.iter)
 
@@ -6157,7 +6271,8 @@
 
 def comprehension_get_ifs(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'comprehension' object has no attribute 'ifs'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'ifs'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_ifs is None:
         if w_self.ifs is None:
@@ -6201,7 +6316,8 @@
 
 def excepthandler_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("'excepthandler' object has no attribute 'lineno'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'lineno'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
@@ -6211,7 +6327,8 @@
 
 def excepthandler_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("'excepthandler' object has no attribute 'col_offset'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'col_offset'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
@@ -6229,7 +6346,8 @@
 
 def ExceptHandler_get_type(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'ExceptHandler' object has no attribute 'type'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'type'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.type)
 
@@ -6239,7 +6357,8 @@
 
 def ExceptHandler_get_name(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'ExceptHandler' object has no attribute 'name'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'name'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
@@ -6249,7 +6368,8 @@
 
 def ExceptHandler_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'ExceptHandler' object has no attribute 'body'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'body'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
@@ -6293,7 +6413,8 @@
 
 def arguments_get_args(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'arguments' object has no attribute 'args'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'args'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_args is None:
         if w_self.args is None:
@@ -6310,7 +6431,8 @@
 
 def arguments_get_vararg(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'arguments' object has no attribute 'vararg'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'vararg'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.vararg)
 
@@ -6323,7 +6445,8 @@
 
 def arguments_get_kwarg(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("'arguments' object has no attribute 'kwarg'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'kwarg'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.kwarg)
 
@@ -6336,7 +6459,8 @@
 
 def arguments_get_defaults(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("'arguments' object has no attribute 'defaults'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'defaults'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_defaults is None:
         if w_self.defaults is None:
@@ -6382,7 +6506,8 @@
 
 def keyword_get_arg(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'keyword' object has no attribute 'arg'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'arg'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.arg)
 
@@ -6392,7 +6517,8 @@
 
 def keyword_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'keyword' object has no attribute 'value'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'value'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
@@ -6427,7 +6553,8 @@
 
 def alias_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("'alias' object has no attribute 'name'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'name'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
@@ -6437,7 +6564,8 @@
 
 def alias_get_asname(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("'alias' object has no attribute 'asname'")
+        typename = space.type(w_self).getname(space)
+        w_err = space.wrap("'%s' object has no attribute 'asname'" % typename)
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.asname)
 

diff --git a/pypy/module/_ast/test/test_ast.py b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -205,29 +205,19 @@
         exc = raises(AttributeError, getattr, x, 'n')
         assert exc.value.args[0] == "'Num' object has no attribute 'n'"
 
+        x = ast.Num(42)
+        assert x.n == 42
+        exc = raises(AttributeError, getattr, x, 'lineno')
+        assert exc.value.args[0] == "'Num' object has no attribute 'lineno'"
+
         skip("WIP")
 
-        x = ast.Num(42)
-        self.assertEquals(x.n, 42)
-        try:
-            x.lineno
-        except AttributeError, e:
-            self.assertEquals(e.args[0],
-                              "'Num' object has no attribute 'lineno'")
-        else:
-            self.assert_(False)
-
         y = ast.Num()
         x.lineno = y
-        self.assertEquals(x.lineno, y)
+        assert x.lineno == y
 
-        try:
-            x.foobar
-        except AttributeError, e:
-            self.assertEquals(e.args[0],
-                              "'Num' object has no attribute 'foobar'")
-        else:
-            self.assert_(False)
+        exc = raises(AttributeError, getattr, x, 'foobar')
+        assert exc.value.args[0] == "'Num' object has no attribute 'foobar'"
 
         x = ast.Num(lineno=2)
         self.assertEquals(x.lineno, 2)


More information about the Pypy-commit mailing list