Michael Hudson mwh21@cam.ac.uk writes:
Guido van Rossum guido@python.org writes:
Then the following could be made essentially equivalent:
f(a,b,c=d,e=f)
dict = {c:d,e:f} f(a,b,**dict)
... except when you have stuff like
f(a,b=c,**kw)
Gruntle. Maybe Python function calls are just complicated! (Has anyone looked at bytecodehacks.xapply? - and that doesn't even handle *-ed and **-ed arguments...).
Hmm - the interaction of "a=b" style args & *-ed args is a bit counter-intuitive, particularly as the "a=b" args syntatically have to come before the *-ed args:
def f(a,b,c,d):
... return a,b,c,d ...
f(1,c=3,*(2,4))
Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: keyword parameter 'c' redefined in call to f()
f(1,b=3,*(2,4))
Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: keyword parameter 'b' redefined in call to f()
f(1,d=4,*(2,3))
(1, 2, 3, 4)
I humbly submit that This Is Wrong. I haven't seen anybody complain about it, which suggests to me that noone is using this combination, and I propose either:
1) banning it 2) demanding that the *-ed arg precede the "a=b" args
Of course, if noone is using this "feature", then maybe this dusty little corner of the language should be left undisturbed.
And I haven't even thought about default arguments yet...
about-to-make-an-opcode-called-BODGE_KEYWORD_ARGUMENTS-ly y'rs M.
Hmm - the interaction of "a=b" style args & *-ed args is a bit counter-intuitive, particularly as the "a=b" args syntatically have to come before the *-ed args:
def f(a,b,c,d):
... return a,b,c,d ...
f(1,c=3,*(2,4))
Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: keyword parameter 'c' redefined in call to f()
f(1,b=3,*(2,4))
Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: keyword parameter 'b' redefined in call to f()
f(1,d=4,*(2,3))
(1, 2, 3, 4)
I humbly submit that This Is Wrong. I haven't seen anybody complain about it, which suggests to me that noone is using this combination, and I propose either:
- banning it
- demanding that the *-ed arg precede the "a=b" args
Interesting. The *-ed arg cannot precede the a=b args currently, but I agree that it would have made more sense to do it that way.
I'm not sure that it's worth allowing the combination of kw args and *tuple, but I'l also not sure that it *isn't* worth it.
Of course, if noone is using this "feature", then maybe this dusty little corner of the language should be left undisturbed.
I think it may be best to leave it alone.
And I haven't even thought about default arguments yet...
That's unrelated.
--Guido van Rossum (home page: http://www.python.org/~guido/)