Issue 8177: Incoherent error with keyword argument follow by unpacking argument lists (original) (raw)
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)
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)
Author: Benjamin Peterson (benjamin.peterson) *
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 "", line 1, in TypeError: f() got multiple values for keyword argument 'foo'
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
Author: Benjamin Peterson (benjamin.peterson) *
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:58
admin
set
github: 52424
2010-04-24 17:47:56
benjamin.peterson
set
status: open -> closed
resolution: wont fix
messages: +
2010-03-21 21:56:16
GhislainHivon
set
messages: +
2010-03-21 21:30:56
benjamin.peterson
set
messages: +
2010-03-21 10:38:58
georg.brandl
set
assignee: benjamin.peterson
nosy: + benjamin.peterson
2010-03-19 15:51:18
GhislainHivon
create