[Twisted-Python] __nonzero__ for Deferred

Justin Mazzola Paluska jmp at justinmp.com
Fri Mar 20 05:05:40 MDT 2015


On 03/18/2015 06:03 PM, Glyph Lefkowitz wrote:
> I'd like to deprecate and remove __nonzero__ on Deferreds.  Occasionally I see code where someone (maybe even me) does "if d:" where they should have been doing "@d.addCallback def cb(result): if result: ...".
>
> Anybody else have this issue?  Objections?

How does this interact with code that uses None as a sentinel?

I have code where I shoot off a recurring process, but want to wait when the 
first run completes.  I do something along the lines of:


d = Deferred()

... setup everything so it calls my callback every time the loop completes ...

if d:
     d.callback("first time completed!")
     d = None

while most of my code uses the check "if d is not None", not all of it does 
(especially the older code).
     --Justin




More information about the Twisted-Python mailing list