[Python-Dev] For review: PEP 285: Adding a bool type

Guido van Rossum guido@python.org
Fri, 08 Mar 2002 11:58:11 -0500


>     >> One question: do True/False behave like None, particularly WRT "is"?
> 
>     Guido> That depends on what the meaning of "is" is. (*)
> 
>     Guido> Yes, there will be only one True and one False.  That's what the
>     Guido> _create flag on the __new__ method was trying to suggest.
> 
> Hmmm...  A boolean type can only take on two values.  I presume you
> will expose True and False through builtins.

Yes.

> Why would you need a __new__ method or any notiong of "creation"?

__new__ must exist in order to support writing

    bool(some_expression)

__new__ returns a reference to the existing False or True object,
except when it is called in the special internal-only mode that is
needed to bootstrap False and True.  The __new__ code should really be
just this:

            def __new__(cls, val=0, _create=0):
                if val:
                    return True
                else:
                    return False

except the Python version must be able to create the instances True
and False.  (Hm, there's another way to create them:

    False = int.__new__(bool, 0)
    True = int.__new__(bool, 1)

I'll change the PEP to use this.)

--Guido van Rossum (home page: http://www.python.org/~guido/)