[Python-Dev] PEP 3102: Keyword-only arguments
"Martin v. Löwis"
martin at v.loewis.de
Mon May 1 07:46:55 CEST 2006
Terry Reedy wrote:
>> Are you asking why that feature (keyword-only arguments) is desirable?
>> That's the whole point of the PEP. Or are you asking why the user
>> shouldn't be allowed to pass keyword-only arguments by omitting the
>> keyword? Because they wouldn't be keyword-only arguments then, anymore.
>
> There are two subproposals: first, keyword-only args after a variable
> number of positional args, which requires allowing keyword parameter
> specifications after the *args parameter, and second, keyword-only args
> after a fixed number number of positional args, implemented with a naked
> '*'. To the first, I said "The rationale for this is pretty obvious.". To
> the second, I asked, and still ask, "Why?".
One reason I see is to have keyword-only functions, i.e. with no
positional arguments at all:
def make_person(*, name, age, phone, location):
pass
which also works for methods:
def make_person(self, *, name, age, phone, location):
pass
In these cases, you don't *want* name, age to be passed in a positional
way. How else would you formulate that if this syntax wasn't available?
(I know it is possible to formulate it elsehow, I'm asking what notation
you would use)
> Again: if a function has a fixed number n of params, why say that the first
> k can be passed by position, while the remaining n-k *must* be passed by
> name?
I see an important use case for k=0 functions, and k=1 methods (where
the only positional argument is self).
Regards,
Martin
More information about the Python-Dev
mailing list