<div dir="ltr">I confess that after reading this thread, and a number of related past ones, I'm still not certain exactly what problem all of this is needed to solve. ISTM that if one has a special function calling requirement to pass in an ordered collection of key/value pairs, one can already just use a special and available call signature for your function:<div>
<br></div><div> def myfunc(a, b, *keyvals):</div><div> od = OrderedDict(keyvals)</div><div> # ... do other stuff</div><div><br></div><div>Call this like:</div><div><br></div><div> value = myfunc(foo, bar, ('a',1), ('z',2), ('b',3))</div>
<div><br></div><div>Yes, it's a slightly special form of the calling convention, but it does something slightly special with its key/val-like arguments, so that seems like a reasonable tradeoff. The solution is purely local to the writer of the function who needs this.</div>
<div><br></div><div>Even if you have an existing OrderedDict that you want to pass in, you can use that like:</div><div><br></div><div> value = myfunc(foo, bar, *myOD.items())</div><div><br></div><div>Of course, if you want to be picky, you could stick in a check at the top of your function definition:</div>
<div><br></div><div> assert all(isinstance(x, tuple) and len(x)==2 for x in keyvals)</div><div><br></div><div><br></div><div> <br><div class="gmail_extra"><br><div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>
from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div></div></div>