[pypy-commit] pypy py3k: Store exception __cause__ differently: first in the OperationError,

amauryfa noreply at buildbot.pypy.org
Tue Oct 18 08:28:23 CEST 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r48181:a736f7e040d3
Date: 2011-10-18 01:13 +0200
http://bitbucket.org/pypy/pypy/changeset/a736f7e040d3/

Log:	Store exception __cause__ differently: first in the OperationError,
	and move it to exception object when it is normalized.

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -19,14 +19,16 @@
 
     _w_value = None
     _application_traceback = None
+    w_cause = None
 
-    def __init__(self, w_type, w_value, tb=None):
+    def __init__(self, w_type, w_value, tb=None, w_cause=None):
         if not we_are_translated() and w_type is None:
             from pypy.tool.error import FlowingError
             raise FlowingError(w_value)
         self.setup(w_type)
         self._w_value = w_value
         self._application_traceback = tb
+        self.w_cause = w_cause
 
     def setup(self, w_type):
         self.w_type = w_type
@@ -205,6 +207,8 @@
                         # raise Type, X: assume X is the constructor argument
                         w_value = space.call_function(w_type, w_value)
                     w_type = self._exception_getclass(space, w_value)
+            if self.w_cause:
+                space.setattr(w_value, space.wrap("__cause__"), self.w_cause)
 
         else:
             # the only case left here is (inst, None), from a 'raise inst'.
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -499,8 +499,7 @@
             w_value = space.call_function(w_type)
         else:
             w_type = space.type(w_value)
-        w_value.w_cause = w_cause
-        operror = OperationError(w_type, w_value)
+        operror = OperationError(w_type, w_value, w_cause=w_cause)
         operror.normalize_exception(space)
         w_traceback = space.w_None # XXX with_traceback?
         if not space.full_exceptions or space.is_w(w_traceback, space.w_None):


More information about the pypy-commit mailing list