[Python-ideas] Ordered storage of keyword arguments (original) (raw)

Chris Rose offline at offby1.net
Fri Oct 29 06:43:48 CEST 2010


On Thu, Oct 28, 2010 at 10:26 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

On 29/10/10 13:54, Nick Coghlan wrote:

The use case is being able to interface naturally with any key-value API where order matters.

For example: # Create an ordered dictionary (WRONG!) d = OrderedDictionary(a=1, b=2, c=3) # Order is actually arbitrary due to unordered kw dict I'd need convincing that the API wouldn't be better designed to take something other than keyword arguments:  d = OrderedDictionary(('a', 1), ('b', 2), ('c', 3)) and have it refuse to accept keyword arguments to prevent accidents.

I'm hard pressed to see how an ordered dict and a dict should be expected to differ by such a degree; in every particular they behave the same, except in the case of the OrderedDict you specify your initial parameters in tuples? Eugh.

I'm not saying that it's a big enough gap to justify the amount of work that so clearly needs to be done (and now that I've followed some of the more indepth comments here, as well as read over the documentation in dictobject.c, I get a sense of how big a deal this could end up being) but there's not a lot to be said for the current weird behaviour of the ordered dict constructor.

-- Chris R.

Not to be taken literally, internally, or seriously. Twitter: http://twitter.com/offby1



More information about the Python-ideas mailing list