PEP 285: Adding a bool type

Ralph Corderoy ralph at inputplus.demon.co.uk
Sat Mar 30 06:39:51 EST 2002


Hi Tim,

> [Guido]
> > > 5) Should operator.truth(x) return an int or a bool.  Tim Peters
> > > believes it should return an int because it's been documented as
> > > such.
> 
> [Ralph Corderoy]
> > Unlike Tim to produce such a poor reason.  Has he been paraphrased
> > a little too much?
> 
> Not in Guido's eyes <wink>.  We don't need 3 equivalent ways to turn
> an arbitrary expression into a bool ("bool(x)" same-as "not not (x)"
> same-as "truth(x)").  *Especially* if str(bool) and repr(bool)
> produce 'True' and 'False', people have a legitimate need to make an
> arbitrary true/false expression produce 0 and 1 too, if only to
> preserve 0/1-based true/false output.  operator.truth() has always
> been the best way to do exactly that.  Alternatives like "(boolexpr)
> + 0" and "(boolexpr) and 1 or 0" and "(0, 1)[boolexpr]" reek in
> comparison.

Aha!  Well, now I've got your side of the argument, and you've
co-incidentally snipped Guido's point of view, I'm firmly in favour of
yours  ;-)

I've happily used `!!x' in C and found `not not x' in Python wordy so
I'm much in favour of operator.truth returning 0 or 1.

Cheers,


Ralph.




More information about the Python-list mailing list