On 9/30/05, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> [Guido van Rossum]
> > __len__ is for sequences and mappings specifically -- everything that
> > supports __getitem__ should have __len__ and everything that has
> > __len__ should have __getitem__.
>
> That's going a bit far.  Unordered collections (like sets and bags) are
> a good counter-example.
>

I've implemented many extension types in C, always to interface
external libraries (the main examples, MPI and PETSc). In those
libraries, some object are invalid (MPI_COMM_NULL) or can get
deallocated in the C side. I always implement a __nonzero__ method for
testing those situations. It sounds a bit bizarre to me to have to
implement a number method for a object that is far from being a
number, and of course __len__ do not make any sense.

Perhaps Py3k could have a more explicit mechanism for definig the
truth value of an object? Something like __bool__ method to be filled
in type object? Any opinions?


Lisandro DalcĂ­n
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to