[Python-ideas] Allow using ** twice

Vince Vinet vince.vinet at gmail.com
Fri Jun 7 05:02:34 CEST 2013


On Thu, Jun 6, 2013 at 10:27 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> In an attempt to frame the discussion more productively:
>
> 1. Python already has a well-defined notion of what it means to merge
> two dictionaries: d1.update(d2)
>

In the context of the original post and using ** multiple times, I am not
so sure about
what it would actually mean to provide the same argument multiple times.
Let us
consider the following call:

>>> foo(a=1, **{"a":2})
Traceback (most recent call last): ...
TypeError: foo() got multiple values for keyword argument 'a'

If functions were to support multiple **kw, an error on multiple keys would
seem (to me)
to be the current behavior. I do not think everyone would have the same
expectation as
me concerning what should happen, or that any particular behavior is
obvious.

As far as providing other ways to do the call itself, functools.partial is
yet another...
partial(foo, **d1)(**d2) which overrides d1 with d2.

-Vince
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130606/3d3ec345/attachment.html>


More information about the Python-ideas mailing list