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

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


On Mon, Mar 2, 2009 at 11:47 AM, Raymond Hettinger <python at rcn.com> wrote:
> [Me]
>>
>> In this case, Armin wants to be able to pass in an ordered dictionary to
>> functions that weren't designed with ordered dicts in mind (config parser,
>> json/yaml parsers, nose, unittest, etc.).  Those functions should be able to
>> assume that all the usual dictionary properties are still true.  In
>> particular, those functions may make internal comparisons to a regular dict
>> (perhaps as a cached value) and would expect those comparisons to succeed.
>
> One other thought:  I was intending to modify namedtuple's _asdict() method
> to return an OrderedDict but don't want to break any existing code that
> relies on the returned object having an order insensitive comparison.

But do you know if any code that relies on that? Have you ever written
any yourself? If you really worry about this so much you could not
make this change, or you'd have to return a custom subclass of odict
that overrides __eq__ again.

> A object that currently returns a dict should be able to return an
> OrderedDict without breaking anything.  The proposed change precludes this
> possibility as well as the ones mentioned above.

Well, such are the joys of strict backwards compatibility. If
something works fine with a dict today, there's no strong need to
return an odict tomorrow. You could always add a new API that returns
an odict.

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


More information about the Python-Dev mailing list