[Python-Dev] Ordering keyword dicts (original) (raw)

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon Jun 10 05:13:43 CEST 2013


On Sun, May 19, 2013 at 1:47 AM, Guido van Rossum <guido at 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]) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130609/f09b6403/attachment.html>



More information about the Python-Dev mailing list