Implicit conversion to boolean in if and while statements

rusi rustompmody at
Tue Jul 17 03:45:51 CEST 2012

On Jul 15, 9:50 pm, Rick Johnson <rantingrickjohn... at> wrote:
> On Sunday, July 15, 2012 11:19:16 AM UTC-5, Ian wrote:
> > On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano
> > <steve+comp.lang.pyt... at> wrote:
> > > (For the record, I can only think of one trap for the unwary: time
> > > objects are false at *exactly* midnight.)
> > Ugh, that's irritating.  I can't think of any scenario where I would
> > ever want the semantics "if timeval (is not midnight):".  This
> > reinforces the point that if you only want to test whether you have
> > None, you should use "is not None" rather than relying on __bool__.
> I think this issue is not so much a "bool test" vs "type test", but more an ambiguous syntax
> issue.

If you know some English, its clear that if and while create bool
[If you know English but have not studied logic the 'if/while' make
sense whereas 'bool' is gobbledygook]

The issue is not where the cast goes to -- this clearly is bool
But where the cast comes from -- which requires tracing program-paths

More information about the Python-list mailing list