Commits

Amaury Forgeot d'Arc committed 0e0490d

Ast objects have a __dict__ and can store any attribute.

Comments (0)

Files changed (3)

pypy/interpreter/astcompiler/ast.py

 
 class AST(Wrappable):
 
-    __slots__ = ("initialization_state",)
+    __slots__ = ("initialization_state", "w_dict")
 
     __metaclass__ = extendabletype
 
     def sync_app_attrs(self, space):
         raise NotImplementedError
 
+    def getdict(self, space):
+        if not hasattr(self, 'w_dict'):
+            self.w_dict = space.newdict(instance=True)
+        return self.w_dict
+
 
 class NodeVisitorNotImplemented(Exception):
     pass
 
 def Module_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Module' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def Interactive_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Interactive' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def Expression_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Expression' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
 
 def Suite_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Suite' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def stmt_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("attribute 'lineno' has not been set")
+        w_err = space.wrap("'stmt' object has no attribute 'lineno'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
 
 def stmt_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("attribute 'col_offset' has not been set")
+        w_err = space.wrap("'stmt' object has no attribute 'col_offset'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
 
 def FunctionDef_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'name' has not been set")
+        w_err = space.wrap("'FunctionDef' object has no attribute 'name'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
 
 def FunctionDef_get_args(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'args' has not been set")
+        w_err = space.wrap("'FunctionDef' object has no attribute 'args'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.args)
 
 
 def FunctionDef_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'FunctionDef' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def FunctionDef_get_decorator_list(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("attribute 'decorator_list' has not been set")
+        w_err = space.wrap("'FunctionDef' object has no attribute 'decorator_list'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_decorator_list is None:
         if w_self.decorator_list is None:
 
 def ClassDef_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'name' has not been set")
+        w_err = space.wrap("'ClassDef' object has no attribute 'name'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
 
 def ClassDef_get_bases(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'bases' has not been set")
+        w_err = space.wrap("'ClassDef' object has no attribute 'bases'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_bases is None:
         if w_self.bases is None:
 
 def ClassDef_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'ClassDef' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def ClassDef_get_decorator_list(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("attribute 'decorator_list' has not been set")
+        w_err = space.wrap("'ClassDef' object has no attribute 'decorator_list'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_decorator_list is None:
         if w_self.decorator_list is None:
 
 def Return_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Return' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Delete_get_targets(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'targets' has not been set")
+        w_err = space.wrap("'Delete' object has no attribute 'targets'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_targets is None:
         if w_self.targets is None:
 
 def Assign_get_targets(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'targets' has not been set")
+        w_err = space.wrap("'Assign' object has no attribute 'targets'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_targets is None:
         if w_self.targets is None:
 
 def Assign_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Assign' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def AugAssign_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'target' has not been set")
+        w_err = space.wrap("'AugAssign' object has no attribute 'target'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
 
 def AugAssign_get_op(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'op' has not been set")
+        w_err = space.wrap("'AugAssign' object has no attribute 'op'")
         raise OperationError(space.w_AttributeError, w_err)
     return operator_to_class[w_self.op - 1]()
 
 
 def AugAssign_get_value(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'AugAssign' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Print_get_dest(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'dest' has not been set")
+        w_err = space.wrap("'Print' object has no attribute 'dest'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.dest)
 
 
 def Print_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'values' has not been set")
+        w_err = space.wrap("'Print' object has no attribute 'values'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
 
 def Print_get_nl(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'nl' has not been set")
+        w_err = space.wrap("'Print' object has no attribute 'nl'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.nl)
 
 
 def For_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'target' has not been set")
+        w_err = space.wrap("'For' object has no attribute 'target'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
 
 def For_get_iter(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'iter' has not been set")
+        w_err = space.wrap("'For' object has no attribute 'iter'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.iter)
 
 
 def For_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'For' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def For_get_orelse(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("attribute 'orelse' has not been set")
+        w_err = space.wrap("'For' object has no attribute 'orelse'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
 
 def While_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'test' has not been set")
+        w_err = space.wrap("'While' object has no attribute 'test'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
 
 def While_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'While' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def While_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'orelse' has not been set")
+        w_err = space.wrap("'While' object has no attribute 'orelse'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
 
 def If_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'test' has not been set")
+        w_err = space.wrap("'If' object has no attribute 'test'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
 
 def If_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'If' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def If_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'orelse' has not been set")
+        w_err = space.wrap("'If' object has no attribute 'orelse'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
 
 def With_get_context_expr(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'context_expr' has not been set")
+        w_err = space.wrap("'With' object has no attribute 'context_expr'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.context_expr)
 
 
 def With_get_optional_vars(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'optional_vars' has not been set")
+        w_err = space.wrap("'With' object has no attribute 'optional_vars'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.optional_vars)
 
 
 def With_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'With' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def Raise_get_type(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'type' has not been set")
+        w_err = space.wrap("'Raise' object has no attribute 'type'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.type)
 
 
 def Raise_get_inst(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'inst' has not been set")
+        w_err = space.wrap("'Raise' object has no attribute 'inst'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.inst)
 
 
 def Raise_get_tback(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'tback' has not been set")
+        w_err = space.wrap("'Raise' object has no attribute 'tback'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.tback)
 
 
 def TryExcept_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'TryExcept' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def TryExcept_get_handlers(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'handlers' has not been set")
+        w_err = space.wrap("'TryExcept' object has no attribute 'handlers'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_handlers is None:
         if w_self.handlers is None:
 
 def TryExcept_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'orelse' has not been set")
+        w_err = space.wrap("'TryExcept' object has no attribute 'orelse'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_orelse is None:
         if w_self.orelse is None:
 
 def TryFinally_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'TryFinally' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def TryFinally_get_finalbody(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'finalbody' has not been set")
+        w_err = space.wrap("'TryFinally' object has no attribute 'finalbody'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_finalbody is None:
         if w_self.finalbody is None:
 
 def Assert_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'test' has not been set")
+        w_err = space.wrap("'Assert' object has no attribute 'test'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
 
 def Assert_get_msg(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'msg' has not been set")
+        w_err = space.wrap("'Assert' object has no attribute 'msg'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.msg)
 
 
 def Import_get_names(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'names' has not been set")
+        w_err = space.wrap("'Import' object has no attribute 'names'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
 
 def ImportFrom_get_module(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'module' has not been set")
+        w_err = space.wrap("'ImportFrom' object has no attribute 'module'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.module)
 
 
 def ImportFrom_get_names(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'names' has not been set")
+        w_err = space.wrap("'ImportFrom' object has no attribute 'names'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
 
 def ImportFrom_get_level(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'level' has not been set")
+        w_err = space.wrap("'ImportFrom' object has no attribute 'level'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.level)
 
 
 def Exec_get_body(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Exec' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
 
 def Exec_get_globals(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'globals' has not been set")
+        w_err = space.wrap("'Exec' object has no attribute 'globals'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.globals)
 
 
 def Exec_get_locals(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'locals' has not been set")
+        w_err = space.wrap("'Exec' object has no attribute 'locals'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.locals)
 
 
 def Global_get_names(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'names' has not been set")
+        w_err = space.wrap("'Global' object has no attribute 'names'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_names is None:
         if w_self.names is None:
 
 def Expr_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Expr' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def expr_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("attribute 'lineno' has not been set")
+        w_err = space.wrap("'expr' object has no attribute 'lineno'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
 
 def expr_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("attribute 'col_offset' has not been set")
+        w_err = space.wrap("'expr' object has no attribute 'col_offset'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
 
 def BoolOp_get_op(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'op' has not been set")
+        w_err = space.wrap("'BoolOp' object has no attribute 'op'")
         raise OperationError(space.w_AttributeError, w_err)
     return boolop_to_class[w_self.op - 1]()
 
 
 def BoolOp_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'values' has not been set")
+        w_err = space.wrap("'BoolOp' object has no attribute 'values'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
 
 def BinOp_get_left(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'left' has not been set")
+        w_err = space.wrap("'BinOp' object has no attribute 'left'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.left)
 
 
 def BinOp_get_op(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'op' has not been set")
+        w_err = space.wrap("'BinOp' object has no attribute 'op'")
         raise OperationError(space.w_AttributeError, w_err)
     return operator_to_class[w_self.op - 1]()
 
 
 def BinOp_get_right(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'right' has not been set")
+        w_err = space.wrap("'BinOp' object has no attribute 'right'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.right)
 
 
 def UnaryOp_get_op(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'op' has not been set")
+        w_err = space.wrap("'UnaryOp' object has no attribute 'op'")
         raise OperationError(space.w_AttributeError, w_err)
     return unaryop_to_class[w_self.op - 1]()
 
 
 def UnaryOp_get_operand(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'operand' has not been set")
+        w_err = space.wrap("'UnaryOp' object has no attribute 'operand'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.operand)
 
 
 def Lambda_get_args(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'args' has not been set")
+        w_err = space.wrap("'Lambda' object has no attribute 'args'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.args)
 
 
 def Lambda_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'Lambda' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
 
 def IfExp_get_test(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'test' has not been set")
+        w_err = space.wrap("'IfExp' object has no attribute 'test'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.test)
 
 
 def IfExp_get_body(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'IfExp' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.body)
 
 
 def IfExp_get_orelse(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'orelse' has not been set")
+        w_err = space.wrap("'IfExp' object has no attribute 'orelse'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.orelse)
 
 
 def Dict_get_keys(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'keys' has not been set")
+        w_err = space.wrap("'Dict' object has no attribute 'keys'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_keys is None:
         if w_self.keys is None:
 
 def Dict_get_values(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'values' has not been set")
+        w_err = space.wrap("'Dict' object has no attribute 'values'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_values is None:
         if w_self.values is None:
 
 def Set_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elts' has not been set")
+        w_err = space.wrap("'Set' object has no attribute 'elts'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
 
 def ListComp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elt' has not been set")
+        w_err = space.wrap("'ListComp' object has no attribute 'elt'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
 
 def ListComp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'generators' has not been set")
+        w_err = space.wrap("'ListComp' object has no attribute 'generators'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
 
 def SetComp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elt' has not been set")
+        w_err = space.wrap("'SetComp' object has no attribute 'elt'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
 
 def SetComp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'generators' has not been set")
+        w_err = space.wrap("'SetComp' object has no attribute 'generators'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
 
 def DictComp_get_key(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'key' has not been set")
+        w_err = space.wrap("'DictComp' object has no attribute 'key'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.key)
 
 
 def DictComp_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'DictComp' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def DictComp_get_generators(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'generators' has not been set")
+        w_err = space.wrap("'DictComp' object has no attribute 'generators'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
 
 def GeneratorExp_get_elt(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elt' has not been set")
+        w_err = space.wrap("'GeneratorExp' object has no attribute 'elt'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.elt)
 
 
 def GeneratorExp_get_generators(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'generators' has not been set")
+        w_err = space.wrap("'GeneratorExp' object has no attribute 'generators'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_generators is None:
         if w_self.generators is None:
 
 def Yield_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Yield' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Compare_get_left(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'left' has not been set")
+        w_err = space.wrap("'Compare' object has no attribute 'left'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.left)
 
 
 def Compare_get_ops(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'ops' has not been set")
+        w_err = space.wrap("'Compare' object has no attribute 'ops'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_ops is None:
         if w_self.ops is None:
 
 def Compare_get_comparators(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'comparators' has not been set")
+        w_err = space.wrap("'Compare' object has no attribute 'comparators'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_comparators is None:
         if w_self.comparators is None:
 
 def Call_get_func(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'func' has not been set")
+        w_err = space.wrap("'Call' object has no attribute 'func'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.func)
 
 
 def Call_get_args(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'args' has not been set")
+        w_err = space.wrap("'Call' object has no attribute 'args'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_args is None:
         if w_self.args is None:
 
 def Call_get_keywords(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'keywords' has not been set")
+        w_err = space.wrap("'Call' object has no attribute 'keywords'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_keywords is None:
         if w_self.keywords is None:
 
 def Call_get_starargs(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("attribute 'starargs' has not been set")
+        w_err = space.wrap("'Call' object has no attribute 'starargs'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.starargs)
 
 
 def Call_get_kwargs(space, w_self):
     if not w_self.initialization_state & 16:
-        w_err = space.wrap("attribute 'kwargs' has not been set")
+        w_err = space.wrap("'Call' object has no attribute 'kwargs'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.kwargs)
 
 
 def Repr_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Repr' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Num_get_n(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'n' has not been set")
+        w_err = space.wrap("'Num' object has no attribute 'n'")
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.n
 
 
 def Str_get_s(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 's' has not been set")
+        w_err = space.wrap("'Str' object has no attribute 's'")
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.s
 
 
 def Attribute_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Attribute' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Attribute_get_attr(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'attr' has not been set")
+        w_err = space.wrap("'Attribute' object has no attribute 'attr'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.attr)
 
 
 def Attribute_get_ctx(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'ctx' has not been set")
+        w_err = space.wrap("'Attribute' object has no attribute 'ctx'")
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
 
 def Subscript_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Subscript' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def Subscript_get_slice(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'slice' has not been set")
+        w_err = space.wrap("'Subscript' object has no attribute 'slice'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.slice)
 
 
 def Subscript_get_ctx(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'ctx' has not been set")
+        w_err = space.wrap("'Subscript' object has no attribute 'ctx'")
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
 
 def Name_get_id(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'id' has not been set")
+        w_err = space.wrap("'Name' object has no attribute 'id'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.id)
 
 
 def Name_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'ctx' has not been set")
+        w_err = space.wrap("'Name' object has no attribute 'ctx'")
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
 
 def List_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elts' has not been set")
+        w_err = space.wrap("'List' object has no attribute 'elts'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
 
 def List_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'ctx' has not been set")
+        w_err = space.wrap("'List' object has no attribute 'ctx'")
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
 
 def Tuple_get_elts(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'elts' has not been set")
+        w_err = space.wrap("'Tuple' object has no attribute 'elts'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_elts is None:
         if w_self.elts is None:
 
 def Tuple_get_ctx(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'ctx' has not been set")
+        w_err = space.wrap("'Tuple' object has no attribute 'ctx'")
         raise OperationError(space.w_AttributeError, w_err)
     return expr_context_to_class[w_self.ctx - 1]()
 
 
 def Const_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Const' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return w_self.value
 
 
 def Slice_get_lower(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'lower' has not been set")
+        w_err = space.wrap("'Slice' object has no attribute 'lower'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lower)
 
 
 def Slice_get_upper(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'upper' has not been set")
+        w_err = space.wrap("'Slice' object has no attribute 'upper'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.upper)
 
 
 def Slice_get_step(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'step' has not been set")
+        w_err = space.wrap("'Slice' object has no attribute 'step'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.step)
 
 
 def ExtSlice_get_dims(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'dims' has not been set")
+        w_err = space.wrap("'ExtSlice' object has no attribute 'dims'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_dims is None:
         if w_self.dims is None:
 
 def Index_get_value(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'Index' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def comprehension_get_target(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'target' has not been set")
+        w_err = space.wrap("'comprehension' object has no attribute 'target'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.target)
 
 
 def comprehension_get_iter(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'iter' has not been set")
+        w_err = space.wrap("'comprehension' object has no attribute 'iter'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.iter)
 
 
 def comprehension_get_ifs(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'ifs' has not been set")
+        w_err = space.wrap("'comprehension' object has no attribute 'ifs'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_ifs is None:
         if w_self.ifs is None:
 
 def excepthandler_get_lineno(space, w_self):
     if not w_self.initialization_state & w_self._lineno_mask:
-        w_err = space.wrap("attribute 'lineno' has not been set")
+        w_err = space.wrap("'excepthandler' object has no attribute 'lineno'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.lineno)
 
 
 def excepthandler_get_col_offset(space, w_self):
     if not w_self.initialization_state & w_self._col_offset_mask:
-        w_err = space.wrap("attribute 'col_offset' has not been set")
+        w_err = space.wrap("'excepthandler' object has no attribute 'col_offset'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.col_offset)
 
 
 def ExceptHandler_get_type(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'type' has not been set")
+        w_err = space.wrap("'ExceptHandler' object has no attribute 'type'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.type)
 
 
 def ExceptHandler_get_name(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'name' has not been set")
+        w_err = space.wrap("'ExceptHandler' object has no attribute 'name'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
 
 def ExceptHandler_get_body(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'body' has not been set")
+        w_err = space.wrap("'ExceptHandler' object has no attribute 'body'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_body is None:
         if w_self.body is None:
 
 def arguments_get_args(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'args' has not been set")
+        w_err = space.wrap("'arguments' object has no attribute 'args'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_args is None:
         if w_self.args is None:
 
 def arguments_get_vararg(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'vararg' has not been set")
+        w_err = space.wrap("'arguments' object has no attribute 'vararg'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.vararg)
 
 
 def arguments_get_kwarg(space, w_self):
     if not w_self.initialization_state & 4:
-        w_err = space.wrap("attribute 'kwarg' has not been set")
+        w_err = space.wrap("'arguments' object has no attribute 'kwarg'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.kwarg)
 
 
 def arguments_get_defaults(space, w_self):
     if not w_self.initialization_state & 8:
-        w_err = space.wrap("attribute 'defaults' has not been set")
+        w_err = space.wrap("'arguments' object has no attribute 'defaults'")
         raise OperationError(space.w_AttributeError, w_err)
     if w_self.w_defaults is None:
         if w_self.defaults is None:
 
 def keyword_get_arg(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'arg' has not been set")
+        w_err = space.wrap("'keyword' object has no attribute 'arg'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.arg)
 
 
 def keyword_get_value(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'value' has not been set")
+        w_err = space.wrap("'keyword' object has no attribute 'value'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.value)
 
 
 def alias_get_name(space, w_self):
     if not w_self.initialization_state & 1:
-        w_err = space.wrap("attribute 'name' has not been set")
+        w_err = space.wrap("'alias' object has no attribute 'name'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.name)
 
 
 def alias_get_asname(space, w_self):
     if not w_self.initialization_state & 2:
-        w_err = space.wrap("attribute 'asname' has not been set")
+        w_err = space.wrap("'alias' object has no attribute 'asname'")
         raise OperationError(space.w_AttributeError, w_err)
     return space.wrap(w_self.asname)
 

pypy/interpreter/astcompiler/tools/asdl_py.py

         else:
             flag = self.data.field_masks[field]
         self.emit("if not w_self.initialization_state & %s:" % (flag,), 1)
-        self.emit("w_err = space.wrap(\"attribute '%s' has not been set\")" %
-                  (field.name,), 2)
+        self.emit("w_err = space.wrap(\"'%s' object has no attribute '%s'\")" %
+                  (name, 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)
 
 class AST(Wrappable):
 
-    __slots__ = ("initialization_state",)
+    __slots__ = ("initialization_state", "w_dict")
 
     __metaclass__ = extendabletype
 
     def sync_app_attrs(self, space):
         raise NotImplementedError
 
+    def getdict(self, space):
+        if not hasattr(self, 'w_dict'):
+            self.w_dict = space.newdict(instance=True)
+        return self.w_dict
+
 
 class NodeVisitorNotImplemented(Exception):
     pass

pypy/module/_ast/test/test_ast.py

         exc = raises(TypeError, ast.Module, 1, 2).value
         msg = str(exc)
         assert msg == "Module constructor takes 0 or 1 positional arguments"
-        raises(AttributeError, ast.Module, nothing=23)
+        ast.Module(nothing=23)
 
     def test_future(self):
         mod = self.get_ast("from __future__ import with_statement")
                                "from __future__ import nested_scopes")
         raises(SyntaxError, compile, mod, "<test>", "exec")
 
+    def test_field_attr_writable(self):
+        import _ast as ast
+        x = ast.Num()
+        # We can assign to _fields
+        x._fields = 666
+        assert x._fields == 666
+
     def test_pickle(self):
         skip("XXX implement me")
         import pickle
         co2 = compile(mod2, "<example>", "exec")
         exec co2 in ns
         assert ns["x"] == 4
+
+    def test_classattrs(self):
+        import ast
+        x = ast.Num()
+        assert x._fields == ('n',)
+        exc = raises(AttributeError, getattr, x, 'n')
+        assert exc.value.args[0] == "'Num' object has no attribute 'n'"
+
+        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)
+
+        try:
+            x.foobar
+        except AttributeError, e:
+            self.assertEquals(e.args[0],
+                              "'Num' object has no attribute 'foobar'")
+        else:
+            self.assert_(False)
+
+        x = ast.Num(lineno=2)
+        self.assertEquals(x.lineno, 2)
+
+        x = ast.Num(42, lineno=0)
+        self.assertEquals(x.lineno, 0)
+        self.assertEquals(x._fields, ('n',))
+        self.assertEquals(x.n, 42)
+
+        self.assertRaises(TypeError, ast.Num, 1, 2)
+        self.assertRaises(TypeError, ast.Num, 1, 2, lineno=0)