def odict(**kwargs):� � � return OrderedDict([(key, kwargs[key]) for key in __kworder__])
�">

(original) (raw)


On Sun, May 19, 2013 at 1:47 AM, Guido van Rossum <guido@python.org> wrote:
I'm slow at warming up to the idea. My main concern is speed -- since

most code doesn't need it and function calls are already slow (and

obviously very common :-) it would be a shame if this slowed down

function calls that don't need it noticeably.


Here is an idea that will not affect functions that don't need to know the order of keywords: a special __kworder__ local variable. �The use of this variable inside the function will signal�compiler to generate additional bytecode to copy keyword names from the stack to a tuple and save it in __kworder__. � �With that feature, an OrderedDict constructor, for example can be written as


def odict(\*\*kwargs):
� � � return OrderedDict(\[(key, kwargs\[key\]) for key in \_\_kworder\_\_\])