[sage-devel] Re: Customizing hash for an instance of ?

Sat, 10 Sep 2011 04:09:04 -0700

The reason for this is that the c source code wich is executed when the 
build in function Hash is executed on a python object wich has as C type 
PyObject then following code is executed (in the latest python 2.6). 

PyObject_Hash(PyObject *v)
{
    PyTypeObject *tp = v->ob_type;
    if (tp->tp_hash != NULL)
        return (*tp->tp_hash)(v);
    /* more code wich in this case doesn't get executed hence isn't relevant

}

So as you can see, as soon as the class of v does have a tp_hash 
attribute/method wich is not NULL it will always call that without looking 
at the attributes of the instance. 

The reason why you get a different behaviour for old style classes is 
because they have a different c type.

To get arround it we would have to hack the python c source code.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to