Message355195
Calls of the form f(name=value, *args) are currently legal syntax. The resulting argument binding is awkward, and almost never does what you want/expect it to:
>>> def f(x, y, z):
... print(x, y, z)
...
>>> f(x=0, *(1, 2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for argument 'x'
>>> f(y=0, *(1, 2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: f() got multiple values for argument 'y'
>>> f(z=0, *(1, 2))
1 2 0
I'm not sure if this is intentional, or an oversight. Every other way of passing positional arguments after keyword arguments results in an error:
f(kwarg=kwarg, arg) # SyntaxError: positional argument follows keyword argument
f(**kwargs, arg) # SyntaxError: positional argument follows keyword argument unpacking
f(**kwargs, *args) # SyntaxError: iterable argument unpacking follows keyword argument unpacking
I think this case should raise a "SyntaxError: iterable argument unpacking follows keyword argument".
I'd like to work on this if we believe it should be changed. |
|
Date |
User |
Action |
Args |
2019-10-23 00:20:42 | brandtbucher | set | recipients:
+ brandtbucher |
2019-10-23 00:20:42 | brandtbucher | set | messageid: <1571790042.34.0.496395652559.issue38560@roundup.psfhosted.org> |
2019-10-23 00:20:42 | brandtbucher | link | issue38560 messages |
2019-10-23 00:20:41 | brandtbucher | create | |
|