[ZODB-Dev] Issue trying to remove elements in OOTreeSet

Marius Gedminas marius at gedmin.as
Fri Sep 24 17:03:41 EDT 2010


On Fri, Sep 24, 2010 at 11:09:58AM -0400, Jim Fulton wrote:
> I wasn't proposing to change anything. :) Breaking inheritance to avoid
> inheriting a bad cmp seems rather too tricky.  (I assume there isn't
> a default comparison in Python 3, although I haven't checked.)
> 
> I suppose that the BTree implementation could check for object's
> bad comparison operator and fail if it sees it. (Details omitted. :)
> 
> This obviously wouldn't happen in 3.10, but might be a fun project for
> someone in 3.11.

What would you think of adding

    def __lt__(self, other):
        if not isinstance(other, Persistent):
            raise ValueError('cannot compare Persistent with %s' % repr(other))
        if self._p_oid is None or other._p_oid is None:
            raise ValueError('cannot compare objects that have no persistent IDs yet; call connection.add()')
        return self._p_oid < other._p_oid

    # define __le__, __gt__, __ge__ in a similar way

to persistent.Persistent?

Marius Gedminas
-- 
The old political syllogism "something must be done: this is something:
therefore this will be done" appears to be at work here, in spades.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20100925/3ec90db6/attachment.bin 


More information about the ZODB-Dev mailing list