[Python-ideas] Preserving **kwargs order
Eric Snow
ericsnowcurrently at gmail.com
Sat Apr 5 20:13:00 CEST 2014
On Apr 4, 2014 2:54 AM, "Terry Reedy" <tjreedy at udel.edu> wrote:
>
> This proposal strikes me as conceptually disordered. A set is not
ordered. An ordered set would be a sequence, and if you want a sequence,
the best thing is to use a sequence object. A dict is a set of key,value
pairs. If you want an ordered sequence of key, value pairs, use a sequence.
OrderedDicts were added for situations where that is not possible because a
pre-existing api requires a mapping object, even though you might prefer to
use a sequence.
With OrderedDict it's about having a mapping and the order of the keys in
one data structure. A sequence of pairs does not an ordered mapping make,
though they may contain the same data.
>
> Passing a sequence of key,value pairs is a case that requires a mapping.
If a function attends to the order of key,value pairs it receives, it
should receive a sequence of such.
>
> **kwds in a call is a substitute for writing out unordered key=value
specifications. The function may or may not have **kargs in its signature
and if it does, the kargs received may or may not be equal to the kwds
passed.
As someone else noted, you write out an *ordered* key=value specification
and that information is lost. In the ** unpacking case, any order
information in the unpacked object is likewise lost. This proposal is all
about preserving that order information in some way without requiring the
caller to extract the order information manually and passing it in
separately.
-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140405/7807c9cb/attachment.html>
More information about the Python-ideas
mailing list