[Python-ideas] OrderedDict for kwargs and class statement namespace

Christian Heimes christian at python.org
Fri Mar 1 00:31:28 CET 2013


Am 28.02.2013 22:53, schrieb Eric Snow:
> Good point.  My own use of **kwargs rarely sees the object leave the
> function or get very big, and this aspect of it just hadn't come up to
> broaden my point of view.  I'm glad we're having this discussion.  My
> intuition is that such a use case would be pretty rare, but even
> then...

I guess most function calls don't need the feature of ordered kwargs.
Could we implement yet another prefix that turns unordered keyword
arguments into ordered keyword arguments, e.g. ***ordkwargs (3 *) and
METH_VARARGS|METH_KEYWORDS|METH_ORDERED PyMethodDef.ml_flags? That would
allow ordered keyword arguments while keeping backward compatibility to
existing programs. Only functions that ask for ordered kwargs would have
to pay the minor performance penalty, too.

I don't know if its feasible or even possible. The interpreter would
have to check the function's flags for each method call in order to
decide if it has to create an ordinary dict or an OrderedDict.

Christian



More information about the Python-ideas mailing list