[ZODB-Dev] __cmp__() for PersistentMapping?
Greg Ward
gward@mems-exchange.org
Thu, 16 Aug 2001 13:38:46 -0400
On 16 August 2001, Jim Fulton said:
> > Of course, this assumes that other is also a PersistentMapping. Hmmm.
>
> Hm indeed, but this is an improvement.
OK, here are two variations on the patch (relative to current CVS). I'm
not sure which one is Zope-ologically correct; the first (isinstance) is
unreliable because isinstance() didn't work with ExtensionClass prior to
Python 2.1. The second (hasattr) is a hack. Take your pick, or do it
your own way, or just ignore me...
VARIATION 1:
--- PersistentMapping.py 16 Aug 2001 17:25:41 -0000 1.11
+++ PersistentMapping.py 16 Aug 2001 17:35:40 -0000
@@ -161,3 +161,5 @@
def __cmp__(self,other):
- return cmp(self._container, other._container)
-
+ if isinstance(other,PersistentMapping):
+ return cmp(self._container, other._container)
+ else:
+ return cmp(self._container, other)
VARIATION 2:
--- PersistentMapping.py 16 Aug 2001 17:25:41 -0000 1.11
+++ PersistentMapping.py 16 Aug 2001 17:35:51 -0000
@@ -161,3 +161,5 @@
def __cmp__(self,other):
- return cmp(self._container, other._container)
-
+ if hasattr(other,'_container'):
+ return cmp(self._container, other._container)
+ else:
+ return cmp(self._container, other)
Greg