22from __future__ import print_function , absolute_import
33
44import sys
5-
65from functools import partial
76
87import attr
98
10- import six
11-
129from ._continuation import trampoline
1310
1411
@@ -34,8 +31,7 @@ def on(self, success=None, error=None):
3431 The result of the Effect will be passed to the first callback. Any
3532 callbacks added afterwards will receive the result of the previous
3633 callback. Normal return values are passed on to the next ``success``
37- callback, and exceptions are passed to the next ``error`` callback
38- as a ``sys.exc_info()`` tuple.
34+ callback, and exceptions are passed to the next ``error`` callback.
3935
4036 If a callback returns an :obj:`Effect`, the result of that
4137 :obj:`Effect` will be passed to the next callback.
@@ -62,7 +58,7 @@ def succeed(self, result):
6258
6359 def fail (self , result ):
6460 """
65- Indicate that the effect has failed. result must be an exc_info tuple .
61+ Indicate that the effect has failed. result must be an exception .
6662 """
6763 self ._cont ((True , result ))
6864
@@ -71,13 +67,13 @@ def guard(f, *args, **kwargs):
7167 """
7268 Run a function.
7369
74- Return (is_error, result), where is_error is a boolean indicating whether
75- it raised an exception. In that case result will be ``sys.exc_info()`` .
70+ Return (is_error, result), where `` is_error`` is a boolean indicating whether
71+ it raised an exception. In that case, `` result`` will be an exception .
7672 """
7773 try :
7874 return (False , f (* args , ** kwargs ))
79- except :
80- return (True , sys . exc_info () )
75+ except Exception as e :
76+ return (True , e )
8177
8278
8379class NoPerformerFoundError (Exception ):
@@ -110,7 +106,7 @@ def perform(dispatcher, effect):
110106 or return another Effect, which will be recursively performed, such that
111107 the result of the returned Effect becomes the result passed to the next
112108 callback. In the case of exceptions, the next error-callback will be called
113- with a ``sys.exc_info()``-style tuple .
109+ with the exception instance .
114110
115111 :returns: None
116112
@@ -123,9 +119,8 @@ def perform(dispatcher, effect):
123119 passed three arguments, not two: the dispatcher, the intent, and a
124120 "box". The box is an object that lets the performer provide the result,
125121 optionally asynchronously. To provide the result, use
126- ``box.succeed(result)`` or ``box.fail(exc_info)``, where ``exc_info`` is
127- a ``sys.exc_info()``-style tuple. Decorators like :func:`sync_performer`
128- simply abstract this away.
122+ ``box.succeed(result)`` or ``box.fail(exc)``, where ``exc`` is
123+ an exception. Decorators like :func:`sync_performer` simply abstract this away.
129124 """
130125 def _run_callbacks (bouncer , chain , result ):
131126 is_error , value = result
@@ -156,8 +151,7 @@ def _perform(bouncer, effect):
156151 effect .intent ,
157152 _Box (partial (bouncer .bounce ,
158153 _run_callbacks , effect .callbacks )))
159- except :
160- e = sys .exc_info ()
154+ except Exception as e :
161155 _run_callbacks (bouncer , effect .callbacks , (True , e ))
162156
163157 trampoline (_perform , effect )
@@ -168,27 +162,25 @@ def catch(exc_type, callable):
168162 A helper for handling errors of a specific type::
169163
170164 eff.on(error=catch(SpecificException,
171- lambda exc_info : "got an error!"))
165+ lambda exc : "got an error!"))
172166
173167 If any exception other than a ``SpecificException`` is thrown, it will be
174168 ignored by this handler and propogate further down the chain of callbacks.
175169 """
176- def catcher (exc_info ):
177- if isinstance (exc_info [ 1 ] , exc_type ):
178- return callable (exc_info )
179- six . reraise ( * exc_info )
170+ def catcher (error ):
171+ if isinstance (error , exc_type ):
172+ return callable (error )
173+ raise error
180174 return catcher
181175
182176
183- def raise_ (exception , tb = None ):
184- """Simple convenience function to allow raising exceptions from lambdas.
185-
186- This is slightly more convenient than ``six.reraise`` because it takes an
187- exception instance instead of needing the type separate from the instance.
177+ def raise_ (exception ):
178+ """Simple convenience function to allow raising exceptions as an expression,
179+ useful in lambdas.
188180
189181 :param exception: An exception *instance* (not an exception type).
190182
191- - ``raise_(exc)`` is the same as ``raise exc``.
192- - ``raise_(exc, tb)`` is the same as ``raise type(exc), exc, tb``.
183+ ``raise_(exc)`` is the same as ``raise exc``.
193184 """
194- six .reraise (type (exception ), exception , tb )
185+ raise exception
186+
0 commit comments