[Python-ideas] Preserving **kwargs order

Eric Snow ericsnowcurrently at gmail.com
Sun Apr 6 00:23:32 CEST 2014

On Apr 5, 2014 3:38 PM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> In the context of serialisation, one key lesson we have learned is that
arbitrary ordering is a problem when you want to minimise spurious diffs,
and sorting isn't a simple solution.

Good point.

> Tools like doctest don't tolerate spurious diffs at all, but are often
amenable to a sorting based answer.
> These *can* all be done today, but *not* by using keyword arguments. In
my view, the problem to be addressed is that keyword arguments *look* like
they should work for these cases, because they have a definite order in the
source code. The only reason they don't work is because the interpreter
throws that ordering information away.
> It's a textbook case of a language feature becoming an attractive
nuisance in some circumstances: the simple and obvious solution for the
above use cases *doesn't actually work* for reasons that aren't obviously
clear if you don't have a firm grasp of Python's admittedly complicated
argument handling.

That's a great way of putting it.

> The simplest way out that I can see? Just make it work, even if that
means also preserving the order of arbitrary keyword arguments in cases
that *dont* need it.

So you're advocating simply using OrderedDict for kwargs?  Ultimately
that's my preference too.  The other options are attempts at addressing
concerns that have come up, particularly Guido's.

Also, "just make it work" must include not having a meaningful impact on
function call performance. :)  That was the big objection to the original
proposal(s) to just switch kwargs to OrderedDict.

> Deciding whether or not to provide a way to opt in to dropping the order
info for speed and memory reasons then becomes a separate optimisation
discussion *after* the current usability trap has been addressed.

Sort of.  The PEP certainly needs to address this point one way or the
other.  Unless Guido relaxes his objections, that is. :)  Regardless, once
I have a draft PEP out the next step will be to implement the OrderedDict
swap and see how things look performance-wise.  It may turn out that the
impact is marginal, at which point the PEP won't have to say much.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140405/e2714b00/attachment-0001.html>

More information about the Python-ideas mailing list