[this is a comment to the answer from @john-la-rooy but I cannot comment yet :) ]
For Python3 compatibility you can do (I was looking for this)
class test(object):
def __bool__(self):
return False
__nonzero__=__bool__
only problem is that you need to repeat the __nonzero__ = __bool__
everytime you change __bool__
in subclasses. Otherwise __nonzero__
will be kept from the superclass. You can try
from builtins import object # needs to be installed !
class test(object):
def __bool__(self):
return False
__nonzero__=__bool__
which should work (not confirmed) or write a metaclass :) yourself.