[Python-Dev] Python Call Mechanism

Michael Hudson mwh21@cam.ac.uk
02 Nov 2000 19:45:47 +0000


Guido van Rossum <guido@python.org> writes:

> > 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
> 
> 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.

Oh, I mostly agree and am not going to put any effort into this area -
but if I or someone else manages to make striking simplifications to
the function call code that has the side effect of banning/changing
the syntax of this combination, then this probably wouldn't be a good
enough reason for its rejection.

> > And I haven't even thought about default arguments yet...
> 
> That's unrelated.

I know, it was just something that occurred to me as adding more
complexity.  Hypothetical excercise: Write a description of Python's
current function call behaviour in sufficient detail to allow
reimplementation of it without playing with an existing interpreter in
less than 1000 words.  It's just hairy, and it amazes me that it feels
so natural most of the time...

Cheers,
M.

-- 
  Not only does the English Language borrow words from other
  languages, it sometimes chases them down dark alleys, hits 
  them over the head, and goes through their pockets.   -- Eddy Peters