[Python-3000] Minor hitch writing the Function Signature PEP
Jim Jewett
jimjjewett at gmail.com
Mon Apr 24 18:02:27 CEST 2006
On 4/23/06, Talin <talin at acm.org> wrote:
>... you can't just do it for a single argument in isolation. You
> have no idea where any positional argument is going to
> go until all keyword arguments have been placed, and
> until all previous positional arguments have
> been placed.
Yes you do.
All positional arguments go to the first (length of positional
arguments) arguments, in exactly that order. If there are leftoevers,
they go to *args. If there is a shortage, then the ones at the end
are not filled by positional.
Then the remaining keyword arguments are filled (or allowed to
default). If any remaining keyword attempts to name one of the
positional arguments that was already filled, a SyntaxError or
TypeError is raised.
>>> def f(a, b, c=5): print a, b ,c
>>> f(26,a=6) # enough arguments, but a is positional
Traceback (most recent call last):
File "<pyshell#3>", line 1, in -toplevel-
f(26,a=6)
TypeError: f() got multiple values for keyword argument 'a'
>>> f(b=15, 4,3) # and the first argument *must* be first
SyntaxError: non-keyword arg after keyword arg
-jJ
More information about the Python-3000
mailing list