Generic singleton

Gregory Ewing greg.ewing at
Sat Mar 6 02:39:25 CET 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'])

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


More information about the Python-list mailing list