On Tue, May 14, 2013 at 5:36 PM, Tim Delaney firstname.lastname@example.org:
On 15 May 2013 09:34, Steven D'Aprano email@example.com wrote:
I don't think that is a particularly good analogy. Stable sorting is intuitively correct. Treating keyword args differently according to their order is intuitively the wrong thing to do, at least most of the time.
The argument *for* an ordered kwargs however is that same one that was used for Enums iterating in definition order by default - it's an ordering that can't be recovered once it's lost.
However, it's not a property that I think is absolutely necessary for kwargs and we shouldn't lose performance to gain that property, but there have been times when I would have liked it.
Barry created a new dict implementation a while back that as a side-effect retained insertion order so long as no keys were removed. That would be suitable IMO for kwargs as a guarantee - definition order so long as nothing has been removed. It was discussed and there was the suggestion to actively break this functionality in order to prevent people relying on it. I'm not sure what the end result of the discussion was off the top of my head.
There was also some conversation at the pycon sprints this year about if keyword arguments could use an ordered dict or not but I wasn't paying enough attention to that to be able to give a summary of what was discussed.
My gut feeling is that it'd add overhead even though I would find it useful at times.