Default __nonzero__ impl doesn't throw a TypeError exception
voidwrk at gmail.com
Thu Jan 8 14:53:23 CET 2009
In Python empty container equals False in 'if' statements:
# prints "It's ok"
if not :
print "It's ok"
Let's create a simple Foo class:
Now I can use Foo objects in 'if' statements:
So, default __nonzero__ impl is to return True. I think, this
behaviour conflicts with 'Explicit is better than implicit' and
'Practicality beats purity' statements. I think, throwing a TypeError
exception would be better. It will result in more explicit code with
More information about the Python-list