[pypy-svn] r9305 - in pypy/branch/dist-interpapp/pypy/objspace: . std

hpk at codespeak.net hpk at codespeak.net
Fri Feb 18 14:20:07 CET 2005


Author: hpk
Date: Fri Feb 18 14:20:06 2005
New Revision: 9305

Modified:
   pypy/branch/dist-interpapp/pypy/objspace/descroperation.py
   pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py
Log:
better AttributeError messages 


Modified: pypy/branch/dist-interpapp/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/descroperation.py	(original)
+++ pypy/branch/dist-interpapp/pypy/objspace/descroperation.py	Fri Feb 18 14:20:06 2005
@@ -5,6 +5,11 @@
 from pypy.interpreter.gateway import BuiltinCode
 from pypy.interpreter.argument import Arguments
 
+def raiseattrerror(space, w_obj, name): 
+    w_type = space.type(w_obj) 
+    msg = "'%s' object has not attribute '%s'" %(w_type.name, name)
+    raise OperationError(space.w_AttributeError, space.wrap(msg))
+
 class Object:
     def descr__getattribute__(space, w_obj, w_name):
         name = space.str_w(w_name)
@@ -17,8 +22,7 @@
             return w_value
         if w_descr is not None:
             return space.get(w_descr, w_obj)
-
-        raise OperationError(space.w_AttributeError, w_name)
+        raiseattrerror(space, w_obj, name) 
 
     def descr__setattr__(space, w_obj, w_name, w_value):
         name = space.str_w(w_name)
@@ -29,7 +33,7 @@
         w_dict = space.getdict(w_obj)
         if w_dict is not None:
             return space.setitem(w_dict, w_name, w_value)
-        raise OperationError(space.w_AttributeError, w_name)
+        raiseattrerror(space, w_obj, name) 
 
     def descr__delattr__(space, w_obj, w_name):
         name = space.str_w(w_name)
@@ -44,7 +48,7 @@
             except OperationError, ex:
                 if not ex.match(space, space.w_KeyError):
                     raise
-        raise OperationError(space.w_AttributeError, w_name)
+        raiseattrerror(space, w_obj, name) 
 
     def descr__init__(space, w_obj, __args__):
         pass   # XXX some strange checking maybe

Modified: pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py	(original)
+++ pypy/branch/dist-interpapp/pypy/objspace/std/typeobject.py	Fri Feb 18 14:20:06 2005
@@ -203,7 +203,8 @@
         return space.get(w_value, space.w_None, w_type)
     if w_descr is not None:
         return space.get(w_descr,w_type)
-    raise OperationError(space.w_AttributeError,w_name)
+    msg = "type object '%s' has no attribute '%s'" %(w_type.name, name)
+    raise OperationError(space.w_AttributeError, space.wrap(msg))
 
 def setattr__Type_ANY_ANY(space, w_type, w_name, w_value):
     name = space.str_w(w_name)



More information about the Pypy-commit mailing list