Frank Niessink:
> OK, so that explains why the id of (two references to the same) 
> instancemethod(s) may differ. But I'm still confused why two 
> instancemethods of two different instances can compare as equal.

I tried to lookup the python source code where the actual comparison 
happens. I think it is in methodobject.c (I'm not familiar with the 
python source so please correct me if I'm wrong), meth_compare. That 
function did not change between python 2.4.4 and 2.5. Moreover, the 
implementation suggests that the only way for two methods to be equal is 
that their instances point to the same object and their method 
definitions are the same. Am I interpreting that correctly?

static int
meth_compare(PyCFunctionObject *a, PyCFunctionObject *b)
{
        if (a->m_self != b->m_self)
                return (a->m_self < b->m_self) ? -1 : 1;
        if (a->m_ml->ml_meth == b->m_ml->ml_meth)
                return 0;
        if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0)
                return -1;
        else
                return 1;
}

I'll dig some deeper in my own code, maybe I have two instances that are 
somehow different with python 2.4 and equal with python 2.5 and that 
register the same method as callback.

Cheers, Frank
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to