__cmp__ between dissimilar objects

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Nov 15 00:49:40 CET 2006

At Tuesday 14/11/2006 19:27, insyte at gmail.com wrote:

> > >Can you point me to a description of this algorithm?  It doesn't seem
> > >to be described in the documentation for the rich comparison or __cmp__
> > >methods...
> >
> > PEP 207
> > http://www.python.org/dev/peps/pep-0207/
>So since I implemented __cmp__ instead of the rich comparison
>operators, Python first tried to reverse the comparison.  This gave
>datetime the opportunity to throw TypeError *before* the interpreter
>failed over to trying __cmp__.
>Is that correct?

Exactly. And if datetime were not so special in its implementation, a 
NotImplementedError (instead of TypeError) would have let your code a 
chance of being executed.

Gabriel Genellina
Softlab SRL 

Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

More information about the Python-list mailing list