[Python-3000] __nonzero__ vs. __bool__

Guido van Rossum guido at python.org
Wed Nov 22 02:12:58 CET 2006


Someone with commit privs please give this one more look over and submit...

On 11/21/06, tomer filiba <tomerfiliba at gmail.com> wrote:
> patch updated (hopefully for the last time. it got me all bored :)
>
>
>
> On 11/21/06, Brett Cannon <brett at python.org > wrote:
> >
> >
> >
> > On 11/21/06, Walter Dörwald <walter at livinglogic.de> wrote:
> > > tomer filiba wrote:
> > > > patch updated
> > >
> > > You're fast! ;)
> > >
> > > AFAICT now we have the following problem: If
> > > Objects/typeobject.c::slot_nb_bool() falls back to
> using __len__(), the
> > > return value of __len__() must be a bool.
> >
> >
> > Why can't the fallback usage just pass the return value from __len__ to
> bool() (forget the C function name) and return that result?  It's just like
> doing::
> >
> >   def bool(obj):
> >       try:
> >           return obj.__bool__()
> >       except AttributeError:
> >           return bool(len(obj))
> >
> > -Brett
> >
> >
> > >
> > > Servus,
> > >    Walter
> > >
> > > > On 11/21/06, *Guido van Rossum* <guido at python.org
> > > > <mailto: guido at python.org>> wrote:
> > > >
> > > >     I think it would set a good example if __bool__ was *required* to
> > > >     return exactly True or False and no other object, not even int
> > > >     instances equal to 0 or 1. Surely that can't be much of a burden.
> Feel
> > > >     free to upload an improved patch.
> > > >
> > > >     On 11/21/06, Walter Dörwald <walter at livinglogic.de
> > > >     <mailto: walter at livinglogic.de>> wrote:
> > > >     > Guido van Rossum wrote:
> > > >     > > On 11/21/06, Ivan Krstić <
> krstic at solarsail.hcs.harvard.edu
> > > >     <mailto:krstic at solarsail.hcs.harvard.edu>> wrote:
> > > >     > >> Guido van Rossum wrote:
> > > >     > >>> Can anyone help out evaluating this patch? If it has to wait
> > > >     for me
> > > >     > >>> it's gonna be a looooooong wait...
> > > >     > >> Looks fine to me functionally, although it seems to
> > > >     gratuitously retab
> > > >     > >> some code that used to be aligned with tabstop 8 to a tabstop
> of 4.
> > > >     > >
> > > >     > > Thanks! I hope you meant "indentation level" instead of
> "tabstop".
> > > >     > > Tomer, can you fix the indentation to be whatever's prevailing
> > > >     in the
> > > >     > > file you're editing?
> > > >     >
> > > >     > Another question is whether __bool__() should be allowed to
> return an
> > > >     > int (or any other object), or if it *must* be a bool. (The patch
> > > >     > currently allows ints). What if __bool__() returns subclasses of
> int,
> > > >     > that overwrite __bool__() themself?
> > > >     >
> > > >     > Servus,
> > > >     >    Walter
> > > >     >
> > > >     >
> > > >
> > > >
> > > >     --
> > > >     --Guido van Rossum (home page: http://www.python.org/~guido/ )
> > > >
> > > >
> > >
> > > _______________________________________________
> > > Python-3000 mailing list
> > > Python-3000 at python.org
> > > http://mail.python.org/mailman/listinfo/python-3000
> > > Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/brett%40python.org
> > >
> >
> >
>
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/guido%40python.org
>
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list