PEP 285: Adding a bool type

Tim Peters tim.one at comcast.net
Sat Mar 30 04:45:04 EST 2002


[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.





More information about the Python-list mailing list