Comparing instances of a dict subclass
<p>I have subclassed dict to add an extra method (so no overriding).</p>

<p>Now, I try to compare two of those subclasses, and I get something weird : </p>

<pre><code>&gt;&gt;&gt; d1.items() == d2.items()
True
&gt;&gt;&gt; d1.values() == d2.values()
True
&gt;&gt;&gt; d1.keys() == d2.keys()
True
&gt;&gt;&gt; d1 == d2
False
</code></pre>

<p><strong>EDIT</strong></p>

<p>That's damn weird ... I don't understand at all ! Anybody with an insight on how the dict.<strong>eq</strong> is implemented ?</p>

<p>Following is all the code :</p>

<pre><code># ------ Bellow is my dict subclass (with no overriding) :

class ClassSetDict(dict):

    def subsetget(self, klass, default=None):
        class_sets = set(filter(lambda cs: klass &lt;= cs, self))
        # Eliminate supersets
        for cs1 in class_sets.copy():
            for cs2 in class_sets.copy():
                if cs1 &lt;= cs2 and not cs1 is cs2:
                    class_sets.discard(cs2)
        try:
            best_match = list(class_sets)[0]
        except IndexError:
            return default
        return self[best_match]

# ------  Then an implementation of class sets

class ClassSet(object):
    # Set of classes, allowing to easily calculate inclusions
    # with comparison operators : `a &lt; B` &lt;=&gt; "A strictly included in B"

    def __init__(self, klass):
        self.klass = klass

    def __ne__(self, other):
        return not self == other

    def __gt__(self, other):
        other = self._default_to_singleton(other)
        return not self == other and other &lt; self

    def __le__(self, other):
        return self &lt; other or self == other

    def __ge__(self, other):
        return self &gt; other or self == other

    def _default_to_singleton(self, klass):
        if not isinstance(klass, ClassSet):
            return Singleton(klass)
        else:
            return klass


class Singleton(ClassSet):

    def __eq__(self, other):
        other = self._default_to_singleton(other)
        return self.klass == other.klass

    def __lt__(self, other):
        if isinstance(other, AllSubSetsOf):
            return issubclass(self.klass, other.klass)
        else:
            return False


class AllSubSetsOf(ClassSet):

    def __eq__(self, other):
        if isinstance(other, AllSubSetsOf):
            return self.klass == other.klass
        else:
            return False

    def __lt__(self, other):
        if isinstance(other, AllSubSetsOf):
            return issubclass(self.klass, other.klass) and not other == self
        else:
            return False

# ------ and finally the 2 dicts that don't want to be equal !!!

d1 = ClassSetDict({AllSubSetsOf(object): (int,)})
d2 = ClassSetDict({AllSubSetsOf(object): (int,)})
</code></pre>
