title: Python - __eq__ method not being called
body: <p>I have a set of objects, and am interested in getting a specific object from the set.  After some research, I decided to use the solution provided here:  <a href="http://code.activestate.com/recipes/499299/" rel="nofollow">http://code.activestate.com/recipes/499299/</a></p>
  
  <p>The problem is that it doesn't appear to be working.</p>
  
  <p>I have two classes defined as such:</p>
  
  <pre><code>class Foo(object):
      def __init__(self, a, b, c):
          self.a = a
          self.b = b
          self.c = c
      def __key(self):
          return (self.a, self.b, self.c)
      def __eq__(self, other):
          return self.__key() == other.__key()
      def __hash__(self):
          return hash(self.__key())
  
  class Bar(Foo):
      def __init__(self, a, b, c, d, e):
          self.a = a
          self.b = b
          self.c = c
          self.d = d
          self.e = e
  </code></pre>
  
  <p>Note:  equality of these two classes should only be defined on the attributes a, b, c.  </p>
  
  <p>The wrapper <code>_CaptureEq</code> in <a href="http://code.activestate.com/recipes/499299/" rel="nofollow">http://code.activestate.com/recipes/499299/</a> also defines its own <code>__eq__</code> method.  The problem is that this method never gets called (I think).  Consider, </p>
  
  <pre><code>bar_1 = Bar(1,2,3,4,5)
  bar_2 = Bar(1,2,3,10,11)
  summary = set((bar_1,))
  assert(bar_1 == bar_2)
  bar_equiv = get_equivalent(summary, bar_2)
  </code></pre>
  
  <p><code>bar_equiv.d</code> should equal 4 and likewise <code>bar_equiv .e</code> should equal 5, but they are not.  Like I mentioned, it looks like the <code>__CaptureEq</code> <code>__eq__</code> method does not get called when the statement <code>bar_2 in summary</code> is executed.  </p>
  
  <p>Is there some reason why the <code>__CaptureEq</code> <code>__eq__</code> method is not being called?  Hopefully this is not too obscure of a question.</p>