Python set __contains__ is not finding objects contained in the set : <p>(python 3.7.1 on linux)</p>

<p>I am observing some strange behavior storing user-defined objects in a set.  The objects are highly complex so a minimal example is not in the cards-- but I am hoping the observed behavior will elicit an explanation from someone wiser than myself.  Here it is:</p>

<pre><code>&gt;&gt;&gt; from mycode import MyObject
&gt;&gt;&gt; a = MyObject(*args1)
&gt;&gt;&gt; b = MyObject(*args2)
&gt;&gt;&gt; a == b
False
&gt;&gt;&gt; z = {a, b}
&gt;&gt;&gt; len(z)
2
&gt;&gt;&gt; a in z
False
</code></pre>

<p>My understanding was that an object is "in" a set if (1) its hash matches the hash of an object in the set and (2) it equals that object.  But those expectations are violated here:</p>

<pre><code>&gt;&gt;&gt; [hash(t) for t in z]
[1013724486348463466, -1852733432963649245]
&gt;&gt;&gt; hash(a)
1013724486348463466
&gt;&gt;&gt; [(hash(t) == hash(a), t == a) for t in z]
[(True, True), (False, False)]
&gt;&gt;&gt; [t is a for t in z]
[True, False]
</code></pre>

<p>And the strangest (syntactically) of all:</p>

<pre><code>&gt;&gt;&gt; [t in z for t in z]
[False, False]
</code></pre>

<p>What might be up with <code>MyObject</code> to cause it to behave this way?  To recap: it has a sane <code>__hash__</code> and <code>__eq__</code> function, <code>set</code> is just a stock python set.  </p>

<p>Here they are specifically:</p>

<pre><code>class MyObject(object):
    ...
        def __hash__(self):
            return hash(self.link)

        def __eq__(self, other):
            """
            two entities are equal if their types, origins, and external references are the same.
            internal refs do not need to be equal; reference entities do not need to be equal
            :return:
            """
            if other is None:
                return False
            try:
                is_eq = (self.external_ref == other.external_ref
                         and self.origin == other.origin
                         and self.entity_type == other.entity_type)
            except AttributeError:
                is_eq = False
            return is_eq
</code></pre>

<p>All of those properties are defined on these objects. As demonstrated above, <code>a == t</code> evaluates to <code>True</code> for one of the objects in the set.  Thanks for any suggestions.</p>
