This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incoherent error with keyword argument follow by unpacking argument lists
Type: Stage:
Components: Interpreter Core Versions: Python 3.1, Python 2.6, Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: GhislainHivon, benjamin.peterson
Priority: normal Keywords:

Created on 2010-03-19 15:51 by GhislainHivon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg101332 - (view) Author: Ghislain Hivon (GhislainHivon) Date: 2010-03-19 15:51
Take a fonction with a parameter and  *args
def foo(bar, args*)
  pass

then call it like this
myargs = [1, 2, 3, 4, 5]
foo(bar=1, *myargs)

The call produce this error : 
TypeError: foo() got multiple values for keyword argument 'bar'

Sould the error be more like : 
SyntaxError: non-keyword arg after keyword arg

the same error if foo was called like this : 
foo(bar=1, myargs)
or
foo(bar=1, 1, 2, 3, 4, 5)
msg101460 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-03-21 21:30
It's a weird error even it reverse order:

>>> def f(foo, *args):
...     pass
...
>>> f(*(1, 2, 3), foo=4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for keyword argument 'foo'
msg101463 - (view) Author: Ghislain Hivon (GhislainHivon) Date: 2010-03-21 21:56
The reverse, f(*(1, 2, 3), foo=4), is consistent with 
f(1,2,3, foo=4)
who also gave 
TypeError: f() got multiple values for keyword argument 'foo'

Which is consistent with the tutorial
http://docs.python.org/tutorial/controlflow.html#keyword-arguments

def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
...
but the following calls would all be invalid:
parrot(voltage=5.0, 'dead')  # non-keyword argument following keyword
parrot(110, voltage=220)     # duplicate value for argument
msg104110 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-04-24 17:47
As covered in http://docs.python.org/dev/reference/expressions.html#calls, this is how function calls are bound.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52424
2010-04-24 17:47:56benjamin.petersonsetstatus: open -> closed
resolution: wont fix
messages: + msg104110
2010-03-21 21:56:16GhislainHivonsetmessages: + msg101463
2010-03-21 21:30:56benjamin.petersonsetmessages: + msg101460
2010-03-21 10:38:58georg.brandlsetassignee: benjamin.peterson

nosy: + benjamin.peterson
2010-03-19 15:51:18GhislainHivoncreate