Re: [Twisted-Python] __nonzero__ for Deferred
> On Mar 20, 2015, at 4:05 AM, Justin Mazzola Paluska 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
Re: [Twisted-Python] __nonzero__ for Deferred
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 ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] __nonzero__ for Deferred
> On Mar 18, 2015, at 5:50 PM, exar...@twistedmatrix.com wrote: > > On 18 Mar, 10:03 pm, gl...@twistedmatrix.com 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? > > Er. What? It's a little early for april fools' day, isn't it? > Seriously, this is weird. Am I missing something? Apparently? > Can expand on what it would mean to deprecated a special method of a class > that doesn't even define it Add such a method and cause it to emit a warning, then raise an exception. > and what makes Deferred unique among all user-defined classes in this regard. As I stated in my original message, there's a class of bug where someone does "if somethingThatReturnsDeferred()". Particularly, "if checkPassword()" is a dangerous manifestation of this class of bug. I'd like this to fail noisily instead of appearing to work. In my opinion, having all user-defined classes implement true truthiness by default is a design error in the language. It's a usually-harmless one except in a few cases, and this is one of those cases, which is why Deferred is not the same as the average user-defined class. -glyph ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] __nonzero__ for Deferred
On 19 March 2015 at 00:03, Glyph Lefkowitz wrote: > I'd like to deprecate and remove __nonzero__ on Deferreds. By "remove" do you mean "add an implementation that raises an exception"? (It seems like this must be what you meant, I just wanted to be clear since this is a slightly subtle issue) I'm not sure offhand if I have any code that would be affected by this, but I don't think I would have a problem considering any such code incorrect. The most likely case I can think of is where I've lazily written something like "if d" instead of "if d is not None". That is to say, "+1". -- mithrandi, i Ainil en-Balandor, a faer Ambar ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] __nonzero__ for Deferred
On 18 Mar, 10:03 pm, gl...@twistedmatrix.com 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? Er. What? It's a little early for april fools' day, isn't it? Seriously, this is weird. Am I missing something? Can expand on what it would mean to deprecated a special method of a class that doesn't even define it and what makes Deferred unique among all user-defined classes in this regard. Jean-Paul ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
[Twisted-Python] __nonzero__ for Deferred
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? -glyph ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python