On Fri, Sep 24, 2010 at 5:03 PM, Marius Gedminas <mar...@gedmin.as> wrote: > 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
Let's not forget __cmp__. :/ > to persistent.Persistent? First, The above code is wrong. :) - It doesn't dispatch to other, which might have custom comparison if its own. - It doesn't take database name into account. More importantly, your suggestion is tantamount to the same mistake Guido made when he gave objects a default comparison operator. If I was going to do anything, I would try to detect when a broken default was used and fail. BTW, I'm happy to see: Python 3.1.2 (r312:79147, Sep 1 2010, 14:43:10) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class C: pass ... >>> c = C() >>> c < None Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: C() < NoneType() >>> C() < C() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: C() < C() :) Jim -- Jim Fulton _______________________________________________ For more information about ZODB, see the ZODB Wiki: http://www.zope.org/Wikis/ZODB/ ZODB-Dev mailing list - ZODB-Dev@zope.org https://mail.zope.org/mailman/listinfo/zodb-dev