Why bool( object )?

Aaron Brady castironpi at gmail.com
Tue Apr 28 08:11:11 CEST 2009


What is the rationale for considering all instances true of a user-
defined type?  Is it strictly a practical stipulation, or is there
something conceptually true about objects?

'''
object.__bool__(self)
If a class defines neither __len__() nor __bool__(), all its instances
are considered true.
'''

This makes it so all objects except False, None, 0, and empty
containers are true by default.  I am not convinced that 'if <a
generic object>' should have any meaning; it should probably throw an
exception.  Is it part of Python's look and feel or its mentality?  Is
it part of the Zen?  Certainly other ideal types can't be cast from
generic objects, so why booleans?  Is it an ineffable component of the
author's vision for the language?  I think that giving arbitrary
syntactic constructs meaning is just space-filler.  It's worse than
syntactic sugar, it's semantic sugar.  Why not assign meanings willy-
nilly to other random juxtapositions of tokens?



More information about the Python-list mailing list