[Python-Dev] A small step to removing the type/class split

Jim Fulton jim@digicool.com
Wed, 25 Oct 2000 08:25:53 -0400


Neil Schemenauer wrote:
> 
> I've run into a problem with ExtensionClass which I believe can
> only be fixed by modifying Python.  I will try to explain.
> 
> I have an ExtensionClass which defines __cmp__.  Depending on the
> objects being compared, the __cmp__ method may never be called.
> This is due to code in object.c that looks like this:
> 
>     if (PyInstance_Check(v) || PyInstance_Check(w)) {
>         try to use use __cmp__ method
>     }
>     else {
>         try number coerce and fall back on type name comparison
>     }
> 
> Extension classes can never pass the PyInstance_Check predicate.
> I've searched for all occurances of PyInstance_Check in the 2.0
> source.  In many places that PyInstance_Check occurs a more
> general "is this an instance-like type" check would seem to be
> more suitable.
> 
> Here is my proposal:

(snip)

I think you got some good answers later in the thread.

I'll point out that a work around is to make your ExtensionClass
a numeric type.  Numeric types have different comparison 
semantics that allow you to get around this limitation.
I did this a few months back for acquisition wrappers.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.