Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: ExtensionClass/Persistent and __cmp__ is tricky

Reply
Thread Tools

Re: ExtensionClass/Persistent and __cmp__ is tricky

 
 
Jim Fulton
Guest
Posts: n/a
 
      06-29-2003
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 private.php?do=newpm&u= Python Powered!
CTO (703) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with max() and __cmp__() Thomas Nelson Python 4 01-29-2007 02:15 AM
a tricky if else(maybe not tricky but impossible) nirkheys@gmail.com C Programming 9 04-25-2006 06:13 PM
dict and __cmp__() question Alex Python 2 09-07-2005 08:29 AM
custom sorting and __cmp__ Lee Harr Python 3 12-03-2003 02:10 AM
RE: ExtensionClass/Persistent and __cmp__ is tricky Tim Peters Python 0 06-29-2003 04:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57