[Python-Dev] Ordering keyword dicts

Chris Angelico rosuav at gmail.com
Tue May 21 00:31:23 CEST 2013

On Mon, May 20, 2013 at 11:35 AM, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Joao S. O. Bueno wrote:
>> Actually, when I was thinking on the subject I came to the same idea, of
>> having
>> some functions marked differently so they would use a different call
>> mechanism -
>> but them I wondered around having a different opcode for the ordered-dict
>> calls.
>> Would that be feasible?
> No, because the callee is the only one that knows whether it
> requires its keyword args to be ordered.
> In fact, not even the callee might know at the time of the
> call. Consider a function that takes **kwds and passes them
> on to another function that requires ordered keywords.

I wouldn't be bothered by that case, as it's no different from any
other means of stuffing a dictionary through **kwds. If you want to
preserve order through a wrapper, the wrapper needs to be declared to
preserve order. The trouble is that there can't be any compile-time
lookup to determine what (type of) function will be called, ergo this
can't be resolved with a unique bytecode based on the destination.

How big a deal would it be to bless OrderedDict with a special literal
notation? Something like:

od = o{'a': 1, 'b': 2, 'c': 3}

Much of the need for ordered kwargs is for constructing OrderedDict
itself after all (cf Antoine).


More information about the Python-Dev mailing list