Recursion limit problems
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat May 12 01:25:51 EDT 2007
En Fri, 11 May 2007 19:17:57 -0300, elventear <elventear at gmail.com>
escribió:
> I am runing into recursion limit problems. I have found that the
> culprit was related to the __hash__ function that I had assigned to
> the objects that were added to a set.
As T. Reedy said, probably you have a recursive structure.
These comments about __hash__, mutability and dict behavior are applicable
to sets too <http://docs.python.org/ref/customization.html#l2h-196> :
"The only required property is that objects which compare equal have the
same hash value; it is advised to somehow mix together (e.g., using
exclusive or) the hash values for the components of the object that also
play a part in comparison of objects. If a class does not define a
__cmp__() method it should not define a __hash__() operation either; if it
defines __cmp__() or __eq__() but not __hash__(), its instances will not
be usable as dictionary keys. If a class defines mutable objects and
implements a __cmp__() or __eq__() method, it should not implement
__hash__(), since the dictionary implementation requires that a key's hash
value is immutable (if the object's hash value changes, it will be in the
wrong hash bucket)."
--
Gabriel Genellina
More information about the Python-list
mailing list