Rich comparison methods don't work in sets?

Matthew Wilson matt at tplus1.com
Fri Jun 19 15:26:03 EDT 2009


On Fri 19 Jun 2009 03:02:44 PM EDT, Gustavo Narea wrote:
> Hello, everyone.
>
> I've noticed that if I have a class with so-called "rich comparison"
> methods
> (__eq__, __ne__, etc.), when its instances are included in a set,
> set.__contains__/__eq__ won't call the .__eq__ method of the elements
> and thus
> the code below:
> """
> obj1 = RichComparisonClass()
> obj2 = RichComparisonClass()

What does 

    >>> obj1 is obj2

return? I don't know anything about set internals.

Matt



More information about the Python-list mailing list