Re: ExtensionClass/Persistent and __cmp__ is tricky

Discussion in 'Python' started by Jim Fulton, Jun 29, 2003.

  1. Jim Fulton

    Jim Fulton Guest

    Tim Peters wrote:
    > [Christian Reis]
    >


    .....

    >>It seems you can't compare ExtensionClass with basic types; in Python
    >>2.1.3 at least it appears to me that try_3way_compare doesn't want to
    >>call tp_compare on the second instance because it's not a PyInstance.

    >
    >
    > Possibly so. I don't think anyone really understands the details of
    > ExtensionClass except for Jim (Fulton), and his understanding was fresh
    > years ago -- ExtensionClass isn't part of Python, it's part of Zope.



    ExtensionClass is a type. There's this funny rule for types and
    __cmp__ that __cmp__ is only called for types when:

    - Comparing objects of the same type or

    - One of the types is a number.

    Otherwise, Python falls back to address comparison.

    This rule is really annoying. You can get around this, as I recall
    by implementing some numeric methods (e.g. __nonzero__). That will make
    Python call EC's __cmp__ more often.

    __cmp__ should be deprecated. Unfortunately, EC doesn't support rich comparisons.
    The good news is that soon, ZODB3 will support new-style classes.

    Jim

    --
    Jim Fulton mailto: Python Powered!
    CTO (703) 361-1714 http://www.python.org
    Zope Corporation http://www.zope.com http://www.zope.org
     
    Jim Fulton, Jun 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim Peters
    Replies:
    0
    Views:
    599
    Tim Peters
    Jun 29, 2003
  2. Lee Harr

    custom sorting and __cmp__

    Lee Harr, Nov 30, 2003, in forum: Python
    Replies:
    3
    Views:
    473
  3. Alex

    dict and __cmp__() question

    Alex, Sep 7, 2005, in forum: Python
    Replies:
    2
    Views:
    279
    Bryan Olson
    Sep 7, 2005
  4. Replies:
    9
    Views:
    547
    CBFalconer
    Apr 25, 2006
  5. gk
    Replies:
    7
    Views:
    1,004
    Tom Anderson
    Oct 12, 2010
Loading...

Share This Page