[Chicago] order of keyword arguments

Igor Sylvester 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?
$0.02
*
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:

add(1, 2)
add(1, y=2)
add(y=2, x=1)

* 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
> http://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20090205/3f8b0f33/attachment.htm>


More information about the Chicago mailing list