[Python-ideas] Why does BoundArguments use an OrderedDict?

random832 at fastmail.us random832 at fastmail.us
Thu Dec 18 17:27:59 CET 2014

On Thu, Dec 18, 2014, at 11:18, Wes Turner wrote:
> > Would it be reasonable to make a lightweight "predictable dict" class
> > that makes a weaker guarantee, e.g. that the enumeration order will
> > match the insertion order in the case where it is filled from empty with
> > no intervening deletions and not guaranteed in any other cases?
> Something like DefaultOrderedDict (like defaultdict)?
> From http://bugs.python.org/issue16991#msg232825 :
> > Would this make it easy/faster to also have a DefaultOrderedDict
> > (which can/could also be accomplished with
> > .get(attr, []) and .setdefault(attr, [])?

Really, I'm thinking more along the lines of a dict that only guarantees
enumeration order (no integer indexed access) in the specific cases
where people "need" it (ordered kwargs for e.g. the OrderedDict
constructor would be another example), while being 'lightweight' enough
(in terms of not having a lot of extra machinery dedicated to
maintaining the order) to ultimately be used as the real dict
implementation (and therefore usable for kwargs, class dictionaries,

Your comment's "DefaultOrderedDict" seems to be more about combining
DefaultDict (default values) and OrderedDict (ordered all the time,
indexed access) rather than anything like having a "default order".

More information about the Python-ideas mailing list