[Twisted-Python] Defer changes

Christopher Armstrong carmstro at twistedmatrix.com
Wed Jul 31 20:50:44 EDT 2002


Two changes to defer.py

1) get rid of 'logError' as default errback. Tv complained about this,
and I agree that it's silly -- logging should happen at the end of the
chain, not at random points during the execution. instead of using
'logError', it now just uses (lambda x: x).

2) Get rid of old PB compatibility thing. We had a check for StringType
in the result of a call/errback, because PB errors used to be strings.
They're not any more. I committed the Failure patch months ago ;-)

And one more thing that I propose, but that's not in this patch:
Enforcing the arguments to errbacks to be Failures. Very confusing
things may happen if you pass something other than a Failure to an
errback, and besides, passing something other than a Failure is like
using 'raise "string"' rather than 'raise MyError("string")'.

Here's the patch:

Index: twisted/internet/defer.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/defer.py,v
retrieving revision 1.12
diff -u -r1.12 defer.py
--- twisted/internet/defer.py	24 Jul 2002 19:04:56 -0000	1.12
+++ twisted/internet/defer.py	1 Aug 2002 00:42:15 -0000
@@ -103,7 +103,7 @@
         These will be executed when the 'master' callback is run.
         """
         cbs = ((callback, callbackArgs, callbackKeywords),
-               (errback or logError, errbackArgs, errbackKeywords))
+               (errback or (lambda x: x), errbackArgs, errbackKeywords))
         if self.default:
             self.callbacks[-1] = cbs
         else:
@@ -228,14 +228,8 @@
                                              callbackArgs=(0,),
                                              errbackArgs=(1,))
                     break
-                if type(self.result) != types.StringType:
-                    # TODO: make this hack go away; it has something to do
-                    # with PB returning strings from errbacks that are
-                    # actually tracebacks that we still want to handle as
-                    # errors sometimes... can't find exactly where right
-                    # now
-                    if not isinstance(self.result, failure.Failure):
-                        self.isError = 0
+                if not isinstance(self.result, failure.Failure):
+                    self.isError = 0
             except:
                 self.result = failure.Failure()
                 self.isError = 1


-- 
                                Chris Armstrong
                         << radix at twistedmatrix.com >>
                http://twistedmatrix.com/users/carmstro.twistd/





More information about the Twisted-Python mailing list