[Python-Dev] PEP 3102: Keyword-only arguments

Joe Smith unknown_kev_cat at hotmail.com
Sun Apr 30 20:05:45 CEST 2006


"Talin" <talin at acm.org> wrote in message news:4453B025.3080100 at acm.org...
> Abstract
>
>     This PEP proposes a change to the way that function arguments are
>     assigned to named parameter slots.  In particular, it enables the
>     declaration of "keyword-only" arguments: arguments that can only
>     be supplied by keyword and which will never be automatically
>     filled in by a positional argument.
>
>
> Rationale
>
>     The current Python function-calling paradigm allows arguments to
>     be specified either by position or by keyword.  An argument can be
>     filled in either explicitly by name, or implicitly by position.
>
>     There are often cases where it is desirable for a function to take
>     a variable number of arguments.  The Python language supports this
>     using the 'varargs' syntax ('*name'), which specifies that any
>     'left over' arguments be passed into the varargs parameter as a
>     tuple.
>
>     One limitation on this is that currently, all of the regular
>     argument slots must be filled before the vararg slot can be.
>
>     This is not always desirable.  One can easily envision a function
>     which takes a variable number of arguments, but also takes one
>     or more 'options' in the form of keyword arguments.  Currently,
>     the only way to do this is to define both a varargs argument,
>     and a 'keywords' argument (**kwargs), and then manually extract
>     the desired keywords from the dictionary.
>

First of all, let me remark that The current python symantics almost 
perfectly
match those of VB6. Sure there is a little bit of syntax differences, but 
overall
they are approximately equivlent. This is actually a good thing

The one area thing that VB6 allows that python does not is optional 
arguments
without a default value. However, what really happens is that the compiler 
assigns a default
value, so it really is only a tiny difference.

The main proposal here adds an aditional feature, and thus will break th 
matching of VB6,
but not in a negative way, as VB6 could benefit from the same extention. So 
I would be +1.

However, I'm not sure what the use case is for keyword only arguments on 
functions
that do *not* accept a variable number of arguments. Could you please 
provide an example use case?





More information about the Python-Dev mailing list