From time to time we see advice to use 'is' when testing against None in Python. I was reminded of that by this checkin (which I should say I don't think is actually a problem)
- self.default = default or update # default value for field + self.default = default==None and update or default At any rate, I got bitten the other day, and I thought I'd pass on the experience just because it's a real-world example of (sometimes) a real need to use 'is'. I had a variable that defaulted to None, but could be bound to a library object (I don't remember just now what the object was). I had written: if variable: blah This often (mostly?) works, though of course it lumps None along with anything else that evaluates to False. However, in this particular case, I got an exception, because the bound object did not have a __nonzero__ method, which is what this test wants to see. Changing to: if variable is None blah fixed the problem. As a relative novice Python handler, I'm trying to develop the habit of using 'is' to test (None, True, False).