keyword parameter order

"Martin v. Löwis" martin at
Sun Nov 18 12:08:59 CET 2007

> I am not sure if this kind of info is available internally to the
> interpreter (ordereddict is in C, so I would even prefer that). Has
> anyone done this or anything like it?

It's not available. See ceval.c:do_call; this fills the dictionary.
>From then on, information about the order of keyword arguments is

> I could probably compile the python interpreter to use ordereddict
> instead of dict and then the parser would insert the keyword
> parameters in specification order in the **kw ordereddict, after which
> iteration over parameters would be ordered.

If you'ld do that literally, you'll find that the keyword arguments are
in reverse order.

> As an aside: I think that allowing dict to be initialised from keyword
> parameters (introduced in Python 2.2 IIRC) was a mistake. This kind of
> use of keyword parameters prevents any real keyword parameters. E.g.
> with 'maxsize' that restricts the dictionary size or 'unique' that
> would throw an Exception if an existing key gets reassigned.

For your own dictionary implementation, you are not required to follow
this interface - in particular if you believe it was a mistake.


More information about the Python-list mailing list