Boolean tests [was Re: Attack a sacred Python Cow]

Carl Banks pavlovevidence at gmail.com
Wed Jul 30 21:26:30 EDT 2008


On Jul 30, 3:56 am, Erik Max Francis <m... at alcyone.com> wrote:
> Carl Banks wrote:
> > I mean in general.  I wouldn't spell it like that.  I would prefer if
> > empty(x), with an __empty__ method.  (And support __nonzero__ aka
> > __bool__ dropped completely.)
>
> So your argument is purely about style, then.  You just wish it were
> written differently.

No, you misunderstand and/or misstate my position again.  I realize I
wasn't as clear as I could have been.  First of all it's not my
"argument": this is a tangent.

There would be a built-in empty, which invokes __empty__, in the same
way len invokes __len__.  It would only be defined for container
types.  (Iterators could choose whether to define it and it would mean
that the iterator is guaranteed stop on the next iteration.  The
iterator is free to read and store the item.  If the iterator doesn't
know whether it will stop, it must not define __empty__ or raise an
exception in it.)  It would become the One Obvious Way to test for
emptiness.  __nonzero__ would disappear and not be replaced with
anything, and objects would not have implicit boolean conversion.


Carl Banks



More information about the Python-list mailing list