PEP 285: Adding a bool type
Tim Peters
tim.one at comcast.net
Sun Mar 31 16:49:21 EST 2002
[Pearu Peterson]
> Theorem:
> ========
> Assume specification of PEP 285. The following statements hold truth:
>
> True is One
>
> and
>
> False is Zero,
>
> where One and Zero represent integers 1 and 0, respectively.
The theorem is false; it would be true if you replaced "is" by "==".
> Proof:
> ------
> According to PEP, True and False are instances of bool that is a
> subclass of int.
True.
> Therefore True and False can be considered as integers
Unclear what that means, exactly.
> and it makes sense to compare them with integers.
Except "is", in terms of which your theorem is stated, is a special kind of
comparison that can reveal non-guaranteed implementation accidents. To cut
this short, there's no guarantee that even
0 is 0
returns true, although it *happens* to be true in all implementations of
CPython to date (although for different internal reasons in different
implementations!). The PEP *does* guarantee that
True is True
False is False
are true; that's a stronger guarantee than is made for integers.
> If n is an integer then the following statements hold
>
> True == n only if n is 1
Only if you're using a non-Python meaning for "is". A true statement using
Python meanings would be
True == n if and only if n == 1
Note that this covers cases like
True == 1.0
too.
> ...
More information about the Python-list
mailing list