[Python-ideas] Preserving **kwargs order

Eric Snow ericsnowcurrently at gmail.com
Thu Apr 3 08:39:32 CEST 2014

On Thu, Mar 20, 2014 at 10:28 AM, Andrew Barnert <abarnert at yahoo.com> wrote:
> And as far as I can see, there is no way to solve this problem. The only way to add keyword order information without breaking all existing forwarding functions is to make the **kwargs parameter always preserve order (and make the **kwargs calling syntax preserve order if present)--that is, to make it always an OrderedDict, which Guido has already rejected.

It's not all that bleak.  Either of the options I outlined should
still work, though option #1 (using a decorator) is better for the
pass-through case that has come up (which I'm not convinced is such a
big deal).  I should have a rough PEP up in a day or two.  Then I'll
get my C OrderedDict applying cleanly and put up an implementation for
the PEP, neither of which *should* take a lot of work.  For what it's
worth, that C implementation isn't all that fancy nor is it very
optimized, but it still performs pretty well (last time I checked it
was mostly the same as dict with the worst operations taking 4 times
longer, which is much better than the pure Python version).

This discussion has gotten me thinking about a related point
(loosening the restriction on ** unpacking), but I'll start another
thread on that one.


More information about the Python-ideas mailing list