On Thu, Jan 20, 2011 at 8:42 AM, Guido van Rossum email@example.com wrote:
On Thu, Jan 20, 2011 at 6:05 AM, M.-A. Lemburg firstname.lastname@example.org wrote:
Nick Coghlan wrote:
On Thu, Jan 20, 2011 at 8:28 PM, Steven D'Aprano email@example.com wrote:
I would be +0 on making **kwargs an ordered dict automatically, and -1 on adding ***ordered_kwargs. Because kwargs is mostly used only for argument passing, and generally with only a small number of items, it probably doesn't matter too much if it's slightly slower than an unordered dict.
Yeah, simply making the kwargs dict always ordered is likely the way we would do it. That's also the only solution with any chance of working by default with the way most decorators are structured (accepting *args and **kwargs and passing them to the wrapped function).
How often do you really need this ?
In which of those cases wouldn't a static code analysis give you the call order of the parameters already ?
"Nice to have" is not good enough to warrant a slow down of all function calls involving keyword arguments, adding overhead for other Python implementations and possibly causing problems with 3rd party extensions relying on getting a PyDict for the keyword arguments object.
What he says.
In addition, I wonder what the semantics would be if the caller passed **d where d was an *unordered* dict...
Wouldn't this be a good argument for the original proposal? That there wouldn't be confusion about whether you were getting an odict or a dict with ***?
Also, would functions that didn't specify this behavior see an actual performance hit? I assumed that given the existence of METH_NOARGS and friends that there was some kind of optimization going on here, but I can't get it to turn up on timeit.