[Python-Dev] PEP 372 -- Adding an ordered directory tocollectionsready for pronouncement

Guido van Rossum guido at python.org
Mon Mar 2 21:21:17 CET 2009


On Mon, Mar 2, 2009 at 12:07 PM, Raymond Hettinger <python at rcn.com> wrote:
> Compromise?
>
>    def __eq__(self, other):
>       if isinstance(other, OrderedDict):
>           return all(map(operator.eq, self.items(), other.items()))
>       if isinstance(other, Mapping):
>           return dict.__eq__(self, other)
>       return NotImplemented # Give other a chance; defaults to False
>
> OrderedDict-to-OrderedDict comparisons are order sensitive -- matching your
> intuition
> OrderedDict-to-OtherMappings -- allow me and Armin to have our
> substitutability for dicts.

This sounds fair. Note that dict.__eq__ actually returns
NotImplemented if not isinstance(other, dict) so you could tighten the
test to isinstance(other, dict) if you wanted to.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list