[Zope-dev] __cmp__ in python classes?

Jim Fulton jim@digicool.com
Tue, 14 Dec 1999 13:29:12 +0000


Benno Rice wrote:
> 
> Hi,
> 
> I've got a system I'm developing that has a bunch of Python classes that
> I'm using.  One of these classes defines a __cmp__ method, but it doesn't
> appear to be being called when I test for equality of two objects.
> 
> I checked to see whether it was Acquisition that was making it interesting
> but even when I got the object directly it wasn't calling my __cmp__
> method.
> 
> Does Zope ignore __cmp__ methods? 

Not in general.

The short answer is that it is a bug in acquisition.
(There's a longer answer having to do with a wrinkle in Python's
comparison rules. Two objects are compared by address if they have
different types unless the types are numberic types. Acquisition
doesn't implement the numeric protocols. With ExtensionClass, 
every class defined a new type.)

> If so, is there any way around it?

A long time ago, Mike Pelletier developed a patch to Acquisition.c
that fixes this by implementing enough of the numeric protocol
to make this work.  I've never gotten around to checking this in.
(Bad me.) 

Mike, do you still have this?  Would you mind checking this in?
(Now that you work for DC. :)

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (888) 344-4332              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.