[pypy-svn] r5341 - pypy/trunk/src/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Sat Jun 26 11:59:20 CEST 2004


Author: arigo
Date: Sat Jun 26 11:59:17 2004
New Revision: 5341

Modified:
   pypy/trunk/src/pypy/interpreter/pyopcode.py
Log:
'raise' handling *still* wasn't completely correct... What if instantiating
the exception class returns some completely unrelated object?


Modified: pypy/trunk/src/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/pyopcode.py	(original)
+++ pypy/trunk/src/pypy/interpreter/pyopcode.py	Sat Jun 26 11:59:17 2004
@@ -315,8 +315,8 @@
         if nbargs >= 3: w_traceback = f.valuestack.pop()
         if nbargs >= 2: w_value     = f.valuestack.pop()
         if 1:           w_type      = f.valuestack.pop()
-        w_resulttuple = prepare_raise(f.space, w_type, w_value, w_traceback)
-        w_type, w_value, w_traceback = f.space.unpacktuple(w_resulttuple, 3)
+        w_resulttuple = prepare_raise(f.space, w_type, w_value)
+        w_type, w_value = f.space.unpacktuple(w_resulttuple, 2)
         tb = f.space.unwrap(w_traceback)
         if tb is not None:
             if not isinstance(tb,pytraceback.PyTraceback):
@@ -833,7 +833,7 @@
     stream.write("\n")
     file_softspace(stream, False)
 
-def app_prepare_raise(etype, value, traceback):
+def app_prepare_raise(etype, value):
     # careful if 'import types' is added here!
     # we get an infinite loop if this import fails:
     #    import types -> IMPORT_NAME -> import_name -> raise ImportError
@@ -841,15 +841,15 @@
     while isinstance(etype, tuple):
         etype = etype[0]
     if isinstance(etype, type):
-        if isinstance(value, etype):
-            # raise Type, Instance: let etype be the exact type of value
-            etype = value.__class__
-        elif value is None:
-            # raise Type: we assume we have to instantiate Type
-            value = etype()
-        else:
-            # raise Type, X: assume X is the constructor argument
-            value = etype(value)
+        if not isinstance(value, etype):
+            if value is None:
+                # raise Type: we assume we have to instantiate Type
+                value = etype()
+            else:
+                # raise Type, X: assume X is the constructor argument
+                value = etype(value)
+        # raise Type, Instance: let etype be the exact type of value
+        etype = value.__class__
     elif type(etype) is str:
         # XXX warn -- deprecated
         if value is not None and type(value) is not str:
@@ -866,7 +866,7 @@
         if not hasattr(value, '__dict__') and not hasattr(value, '__slots__'):
             raise TypeError("raising built-in objects can be ambiguous, "
                             "use 'raise type, value' instead")
-    return etype, value, traceback
+    return etype, value
 
 def app_find_metaclass(bases, namespace, globals):
     if '__metaclass__' in namespace:



More information about the Pypy-commit mailing list