> On Mar 20, 2015, at 4:05 AM, Justin Mazzola Paluska <j...@justinmp.com> wrote:
> 
> 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

That's why we would have a warning first, so you'd have an opportunity to fix 
it.  Given that Deferred is so central and widely used, we might want to wait 
more than the required minimum of one release before turning that warning into 
an exception.

The "right" way to check against None is always to use "if x is not None", not 
"if x"; there are lots of other reasons.

-g

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to