PEP 285: Adding a bool type

Pearu Peterson pearu at cens.ioc.ee
Sun Mar 31 18:07:29 EST 2002


On 31 Mar 2002, Martin v. Loewis wrote:

> Pearu Peterson <pearu at cens.ioc.ee> writes:
> 
> > Just a random thought ...
> > 
> > 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.
> 
> It depends on what the meaning of 'is' is. Did you mean 'is' in the
> Python sense of checking identity? Then this theorem can't possibly
> true: type(One) is int and type(True) is bool implies One is not True.

Sure, this theorem could be improved for correctness by starting defining
the meanings of words.

I could not use "is" in Python sense because Python does not define
objects One and Zero (note the use "represent" instead of "are"), for
instance. I used "is" in a general sense that in some cases coincides
with the Python "is" (as Tim already mentioned, also the 0 is 0 issue).

> > Proof:
> > ------
> > According to PEP, True and False are instances of bool that is a subclass
> > of int. Therefore True and False can be considered as integers and it
> > makes sense to compare them with integers. If n is an integer then the
> > following statements hold
> > 
> >   True == n   only if n is 1
> > 
> > and
> > 
> >   False == n  only if n is 0.
> 
> That is correct. However, a==b does not imply a is b.

Sure. My main point with this theorem is that the above statements hold
even if n is an arbitrary python object ("is" in a general sense). 
Therefore I find objects True and 1 the same (and questioning the
necessity for introducing bool). They are not the same in Python
"is" sense but this is irrelevant (as an implementation issue): Python
"is" only compares Python objects and not the concepts that these objects
represent. 

Later being more important to me, though, using the former quite often
with None. (BTW, None has not always the meaning of False, but the
meaning of "don't know" or "default", like in distutils).

Pearu





More information about the Python-list mailing list