11# -*- test-case-name: effect.test_base -*-
2- from __future__ import print_function , absolute_import
3-
4- import sys
5-
62from functools import partial
73
84import attr
95
10- import six
11-
126from ._continuation import trampoline
137
148
@@ -34,8 +28,7 @@ def on(self, success=None, error=None):
3428 The result of the Effect will be passed to the first callback. Any
3529 callbacks added afterwards will receive the result of the previous
3630 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.
31+ callback, and exceptions are passed to the next ``error`` callback.
3932
4033 If a callback returns an :obj:`Effect`, the result of that
4134 :obj:`Effect` will be passed to the next callback.
@@ -62,7 +55,7 @@ def succeed(self, result):
6255
6356 def fail (self , result ):
6457 """
65- Indicate that the effect has failed. result must be an exc_info tuple .
58+ Indicate that the effect has failed. result must be an exception .
6659 """
6760 self ._cont ((True , result ))
6861
@@ -71,13 +64,13 @@ def guard(f, *args, **kwargs):
7164 """
7265 Run a function.
7366
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()`` .
67+ Return (is_error, result), where `` is_error`` is a boolean indicating whether
68+ it raised an exception. In that case, `` result`` will be an exception .
7669 """
7770 try :
7871 return (False , f (* args , ** kwargs ))
79- except :
80- return (True , sys . exc_info () )
72+ except Exception as e :
73+ return (True , e )
8174
8275
8376class NoPerformerFoundError (Exception ):
@@ -110,7 +103,7 @@ def perform(dispatcher, effect):
110103 or return another Effect, which will be recursively performed, such that
111104 the result of the returned Effect becomes the result passed to the next
112105 callback. In the case of exceptions, the next error-callback will be called
113- with a ``sys.exc_info()``-style tuple .
106+ with the exception instance .
114107
115108 :returns: None
116109
@@ -123,9 +116,8 @@ def perform(dispatcher, effect):
123116 passed three arguments, not two: the dispatcher, the intent, and a
124117 "box". The box is an object that lets the performer provide the result,
125118 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.
119+ ``box.succeed(result)`` or ``box.fail(exc)``, where ``exc`` is
120+ an exception. Decorators like :func:`sync_performer` simply abstract this away.
129121 """
130122 def _run_callbacks (bouncer , chain , result ):
131123 is_error , value = result
@@ -156,8 +148,7 @@ def _perform(bouncer, effect):
156148 effect .intent ,
157149 _Box (partial (bouncer .bounce ,
158150 _run_callbacks , effect .callbacks )))
159- except :
160- e = sys .exc_info ()
151+ except Exception as e :
161152 _run_callbacks (bouncer , effect .callbacks , (True , e ))
162153
163154 trampoline (_perform , effect )
@@ -168,27 +159,24 @@ def catch(exc_type, callable):
168159 A helper for handling errors of a specific type::
169160
170161 eff.on(error=catch(SpecificException,
171- lambda exc_info : "got an error!"))
162+ lambda exc : "got an error!"))
172163
173164 If any exception other than a ``SpecificException`` is thrown, it will be
174165 ignored by this handler and propogate further down the chain of callbacks.
175166 """
176- def catcher (exc_info ):
177- if isinstance (exc_info [ 1 ] , exc_type ):
178- return callable (exc_info )
179- six . reraise ( * exc_info )
167+ def catcher (error ):
168+ if isinstance (error , exc_type ):
169+ return callable (error )
170+ raise error
180171 return catcher
181172
182173
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.
174+ def raise_ (exception ):
175+ """Simple convenience function to allow raising exceptions as an expression,
176+ useful in lambdas.
188177
189178 :param exception: An exception *instance* (not an exception type).
190179
191- - ``raise_(exc)`` is the same as ``raise exc``.
192- - ``raise_(exc, tb)`` is the same as ``raise type(exc), exc, tb``.
180+ ``raise_(exc)`` is the same as ``raise exc``.
193181 """
194- six . reraise ( type ( exception ), exception , tb )
182+ raise exception
0 commit comments