[pypy-svn] r31487 - in pypy/dist/pypy/interpreter: . test

mwh at codespeak.net mwh at codespeak.net
Tue Aug 22 17:08:37 CEST 2006


Author: mwh
Date: Tue Aug 22 17:08:18 2006
New Revision: 31487

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/test/test_raise.py
Log:
(ac, mwh)
fix abstract_getclass to cope with old-style classes -- see test.
this broke "./pypy-c-oldstyle translate.py"...


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Tue Aug 22 17:08:18 2006
@@ -638,7 +638,12 @@
             return self.w_True
 
     def abstract_getclass(self, w_obj):
-        return self.getattr(w_obj, self.wrap('__class__'))
+        try:
+            return self.getattr(w_obj, self.wrap('__class__'))
+        except OperationError, e:
+            if e.match(self, self.w_TypeError) or e.match(self, self.w_AttributeError):
+                return self.type(w_obj)
+            raise
 
     def eval(self, expression, w_globals, w_locals):
         "NOT_RPYTHON: For internal debugging."

Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Tue Aug 22 17:08:18 2006
@@ -303,14 +303,6 @@
         return space.wrap(Method(space, w_function, None, w_cls))
 
 
-def _getclass(space, w_obj):
-    try:
-        return space.abstract_getclass(w_obj)
-    except OperationError, e:
-        if e.match(space, space.w_AttributeError):
-            return space.type(w_obj)
-        raise
-
 class Method(Wrappable):
     """A method is a function bound to a specific instance or class."""
 
@@ -353,7 +345,7 @@
                 if w_firstarg is None:
                     instdescr = "nothing"
                 else:
-                    instname = _getclass(space, w_firstarg).getname(space,"")
+                    instname = self.abstract_getclass(space, w_firstarg).getname(space,"")
                     if instname:
                         instname += " "
                     instdescr = "%sinstance" %instname

Modified: pypy/dist/pypy/interpreter/test/test_raise.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_raise.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_raise.py	Tue Aug 22 17:08:18 2006
@@ -123,3 +123,11 @@
         except B, b:
             assert b.__class__ == B
             assert b.x == 42
+
+    def test_it(self):
+        C = _classobj('C', (), {})
+        # this used to explode in the exception normalization step:
+        try:
+            {}[C]
+        except KeyError:
+            pass



More information about the Pypy-commit mailing list