Exemple #1
0
 def __eq__(self, other):
     if isinstance(other, (OrderedBidirectionalMapping, OrderedDict)):
         if len(self) != len(other):
             return False
         for i, j in izip(iteritems(self), iteritems(other)):
             if i != j:
                 return False
         return True
     if isinstance(other, Mapping):
         return Mapping.__eq__(self, other)
     return False
        def __eq__(self, other):
            """
            Generated by @autodict.
            In the case the other is of the same type, use the dict comparison. Otherwise, falls back to super.

            :param self:
            :param other:
            :return:
            """
            # in the case the other is of the same type, use the dict comparison, that relies on the appropriate fields
            if isinstance(other, cls):
                return dict(self) == dict(other)
            elif isinstance(other, Mapping):
                return dict(self) == other
            else:
                # else fallback to inherited behaviour, whatever it is
                try:
                    f = super(cls, self).__eq__
                except AttributeError:
                    # can happen in python 2 when adding Mapping inheritance failed
                    return Mapping.__eq__(dict(self), other)
                else:
                    return f(other)