On Thu, Apr 10, 2014 at 4:04 PM, Barry Warsaw <barry@python.org> wrote:
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}
?
So preserve the type of the object passed in? Perhaps. However, using keyword args for OrderedDict loses order, so that would put us right back at the status quo anyway!
Okay, if you call it with keyword syntax, e.g.
foo(a=3, b=2, c=1) {'c': 1, 'a': 3, 'b': 2}
Which is the main use case (rather than that of handling just unpacked args--which incidentally is a more complicated proposal). -eric