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

Neil Schemenauer nas@arctrix.com
Tue, 24 Oct 2000 07:37:12 -0700

On Tue, Oct 24, 2000 at 04:50:32PM -0500, Guido van Rossum wrote:
> Rather than formalizing the exceptions made for instances, we
> should work on eradicating the differences between classes and
> types.

Yes, I see this now.  Those PyInstance_Check() calls should
really go away.  Instead, the type should be responsible for
providing different behavior.

> I believe that the plans for rich comparisons would or could
> also take care of this.

I've just briefly looked at the proposal.  It consists of two
parts.  One is splitting __cmp__ into __gt__, __lt__, etc.  That
is a separate issue to the one we are dicussing.  The other part
is directly related.  In order for types to define their own
comparison behavior, it proposes that types have an optional
pointer to a rich comparison function in the type structure.  I
think this is the right idea but it doesn't go far enough.  Every
operation should be implementable by the type.  Code like:

    if (PyString_Check(obj)) {
    else if (PyInstance_Check(obj)) {
        something else

should disappear unless it is need for performance reasons.  I
think we are close to achieving this goal.  I'll try to come up
with a proposal.