[Python-Dev] Ordering keyword dicts
solipsis at pitrou.net
Sun May 19 15:01:48 CEST 2013
On Sat, 18 May 2013 22:47:35 -0700
Guido van Rossum <guido at python.org> wrote:
> On Sat, May 18, 2013 at 10:27 PM, Raymond Hettinger
> <raymond.hettinger at gmail.com> wrote:
> > BTW, I'm +1 on the idea for ordering keyword-args. It makes
> > it easier to debug if the arguments show-up in the order they
> > were created. AFAICT, no purpose is served by scrambling them
> > (which is exacerbated by the new randomized hashing security feature).
> I'm slow at warming up to the idea. My main concern is speed -- since
> most code doesn't need it and function calls are already slow (and
> obviously very common :-) it would be a shame if this slowed down
> function calls that don't need it noticeably.
> An observation is that it's only necessary to preserve order if the
> function definition uses **kwds. AFAIK we currently don't know if this
> is the case when the call is made though, but perhaps the information
> could be made available to the call site somehow.
> There are also many special cases to consider; e.g. using **kwds in
> the call where kwds is an unordered dict, or calls from C, or calls to
> But maybe someone considers this a challenge and comes up with a
> patch? The benefits to *some* use cases would be obvious.
The main use case seems to be the OrderedDict constructor itself.
Otherwise, I can't think of any situation where I would've wanted it.
Changing keyword arguments to be an OrderedDict without impacting
performance in all the cases you mentioned (and without breaking
C-level compatibility) would be a real, tough challenge.
More information about the Python-Dev