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

Raymond Hettinger python at rcn.com
Mon Mar 2 17:43:05 CET 2009


[Antoine Pitrou] 
> Given you were bitten by it in your own unit tests (the "eval(repr()) does not
> maintain ordering" problem pointed by Georg),

Completely unrelated.  The original test passed because the arbitrarily
ordered data in the regular dict happened to match the order added in
a regular dict because I didn't shuffle the keys.  There was no direct
dict-to-ordered dictcomparison.  Had the __eq__ method been defined
differently, the test still would have passed (had a false positive).


> I think it would be better to
> reconsider the current __eq__ behaviour, and make it ordering-aware.

If someone wants to explicitly ask for an order-sensitive comparison,
the docs give a clear, simple example of how to do that.  Otherwise,
it's best to leave regular dict equality in-place because OrderedDicts
need to be substitutable anywhere dicts are used and some of those
places may make the assumption that order insensitive compares are
being used.  

Also, the PEP outlines another issue with trying to make 
comparisons order sensitive.  It leads to weirdness with
ordereddict-to-dict comparisons making a behavior shift
based on the type of one of the two inputs.  It's just asking
for problems and it introduces an unnecessary difference
from regular dicts.   

Given that either choice will be surprising to someone, we opted
for the simplest API with the fewest special cases and made sure
the choice was clearly noted in the docs.


Raymond





More information about the Python-Dev mailing list