[Chicago] order of keyword arguments
igorsyl at gmail.com
Thu Feb 5 13:20:22 CET 2009
Thanks for your comments.
*Doesn't it just go against the design of Python? Dictionaries don't
care about order, so if you do, use something other than a dictionary?
You can pass a list or something? Don't use the **kwargs feature?
My suggestion is not to change the dict object but perhaps make kwargs an
instance of a subclass of dict. The kwargs instance would know about the
ordering of the keyword arguments.
Alternatively, the inspect module can be amended with code that introspects
the frame to figure this out.
*What is the use case for this?
I want to use the foo(A=1,B=2) notation instead of foo(('A', 1), ('B', 2)),
where the order of the elements matter.
*You could try, but I doubt it'd get any traction. After all, if you do
func(**kw) there's no possible way to capture the order of the keyword
arguments, since the underlying dictionary didn't have an order. Also you
have to remember that for:
def add(x, y): return x+y
these function calls are all equivalent:
* I'm not sure I understand your example. The function signature is
foo(**kargs) so calls to foo(1,2) and foo(1,B=2) would fail with a
TypeError. foo(A=1,B=2) would work.
On Wed, Feb 4, 2009 at 11:48 PM, Ian Bicking <ianb at colorstudy.com> wrote:
> On Wed, Feb 4, 2009 at 11:33 PM, Igor Sylvester <ias at alum.mit.edu> wrote:
>> Is this worthy of a PEP?
> You could try, but I doubt it'd get any traction. After all, if you do
> func(**kw) there's no possible way to capture the order of the keyword
> arguments, since the underlying dictionary didn't have an order. Also you
> have to remember that for:
> def add(x, y): return x+y
> these function calls are all equivalent:
> add(1, 2)
> add(1, y=2)
> add(y=2, x=1)
> Ian Bicking | http://blog.ianbicking.org
> Chicago mailing list
> Chicago at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Chicago