[Python-ideas] Programming recommendations (PEP 8) and boolean values

Ethan Furman ethan at stoneleaf.us
Thu Aug 9 21:00:08 CEST 2012


Ned Batchelder wrote:
> On 8/8/2012 4:29 PM, Georg Brandl wrote:
>> For None, "==" and "is" are equivalent, because no other object is equal
>> to None.  For True and False, this is different, and using "is" here is
>> a very stealthy bug. 
 >
> It's easy to make other objects == None, by writing buggy __eq__ 
> methods.  That doesn't happen much, but it's easier with __ne__, where 
> the negated logic is easy to screw up.  I've seen it happen. Use "is 
> None", not "== None".

It's also easy to make objects == None because that's the behavior you 
want.  Like most things, there are exceptions to the rules, and you need 
to know the package you are dealing with to use it properly.

~Ethan~



More information about the Python-ideas mailing list