Generic singleton

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Mar 5 20:39:25 EST 2010


I think the important difference between None and booleans
wrt singleton behaviour is that things are often compared
with None using "is", so it's quite important that there
only be one instance of NoneType around, and it makes
sense not to give people the false impression that they
can create another one.

Re-using predefined True and False instances is more of
a performance optimisation, however -- they're not usually
compared for identity, or even compared at all for that
matter. So there's no particular reason to disallow
calling bool().

In fact, there's an excellent reason to *allow* calling
it: not only is bool a type, it's also often used as a
function to coerce things to a boolean value:

    >>> bool(['hello'])
    True

There's no equivalent reason to make NoneType callable,
as coercing something to None makes very little sense.

-- 
Greg



More information about the Python-list mailing list