[Python-ideas] bool keyword: (was [Python-Dev] bool conversion wart?)

Collin Winter collinw at gmail.com
Sat Mar 3 01:27:23 CET 2007

On 3/2/07, Ron Adam <rrr at ronadam.com> wrote:
> Josiah Carlson wrote:
> > Ron Adam <rrr at ronadam.com> wrote:
> >> Interpretation:
> >>
> >> The "small" inconsistency (if any) here is the 'not' keyword vs the
> >> 'bool()' constructor. They pretty much do the same thing yet work in
> >> modestly different ways.
> >
> > Maybe I'm missing something, but is there a place where the following is
> > true?
> >
> >     (not not x) != bool(x)
> >
> > I can't think of any that I've ever come across.
> >
> >  - Josiah
> I don't think you are missing anything.  I did say it was a *small*
> inconsistency in how they are used in relation to 'and', 'or' and 'not'.
> ie.. a constructor vs a keyword in a similar situation.

'and', 'or' and 'not' are operators (and hence keywords) because
making them functions is incredibly ugly: and(or(a, b), not(c)).

Changing "bool(x)" to "bool x" introduces a much larger inconsistency
between bool and the other built-in types.

> And I also pointed out it doesn't change what they do, it has more to do
> with how they work underneath and that there may be some benefits in
> changing this.

So the main reason is for optimization? Are you really calling bool()
frequently in inner-loop code? Is a profiler telling you that bool()
is a bottleneck in your applications?

Collin Winter

More information about the Python-ideas mailing list