[Python-3000] __nonzero__ vs. __bool__

Terry Reedy tjreedy at udel.edu
Wed Nov 22 02:36:32 CET 2006


"Brett Cannon" <brett at python.org> wrote in message 
news:bbaeab100611211232r53de3c33p915bee7b49dbdf9a at mail.gmail.com...

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))
------------

If an object without __bool__ returned itself as its length, this would be 
an infinite loop, at least in this Python version.  Do we worry about 
something so crazy?

tjr





More information about the Python-3000 mailing list