[Python-ideas] Proto-PEP: Preserving the order of **kwargs in a function.
Barry Warsaw
barry at python.org
Fri Apr 11 00:04:49 CEST 2014
Wouldn't another, much less invasive, much more explicit approach be to not
squash subclasses of dict when passed into **args?
IOW, the way to preserve order would be:
>>> def foo(**kws):
... print(kws)
...
>>> from collections import OrderedDict as od
>>> foo(**od(a=1, b=2, c=3))
OrderedDict([('a', 1), ('c', 3), ('b', 2)])
>>> # instead of: {'a': 1, 'c': 3, 'b': 2}
?
Okay, if you call it with keyword syntax, e.g.
>>> foo(a=3, b=2, c=1)
{'c': 1, 'a': 3, 'b': 2}
but oh well.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140410/f4e4b65c/attachment.sig>
More information about the Python-ideas
mailing list