Recursion limit problems

Diez B. Roggisch deets at nospam.web.de
Tue May 15 08:28:52 EDT 2007


> with the same hash value.
> That is, you should define __hash__ and one of (__cmp__ or __eq__).
> __neq__ (inequality) isn't required nor used by dict/set implementation.
> (Anyway, Python will transform a!=b into not(a==b), if __neq__ isn't
> defined). Neither <, <=, >, >= are used.

No, it won't:

http://docs.python.org/ref/customization.html#l2h-190

"""
There are no implied relationships among the comparison operators. The truth
of x==y does not imply that x!=y is false. Accordingly, when defining
__eq__(), one should also define __ne__() so that the operators will behave
as expected.
"""

---------------------
class Foo(object):

    def __eq__(self, other):
        print "__eq__"
        return id(self) == id(other)

    
Foo() == Foo()
Foo() != Foo()
---------------

will give you only one call to __eq__

Diez



More information about the Python-list mailing list