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

"Martin v. Löwis" martin at v.loewis.de
Mon May 1 19:26:41 CEST 2006


Terry Reedy wrote:
> This is not a reason for subproposal two, but a special case, as you 
> yourself note below, and hence does say why you want to have such.
> 
>> def make_person(*, name, age, phone, location):
>>    pass

You weren't asking for a reason, you were asking for an example:
this is one.

> And again, why would you *make* me, the user-programmer, type
> 
> make_person(name=namex, age=agex, phone=phonex, location = locationx)
> #instead of
> make_person(namex,agex,phonex,locationx)
> ?

Because there should be preferably only one obvious way to call that
function. Readers of the code should not need to remember the
order of parameters, instead, the meaning of the parameters should
be obvious in the call. This is the only sane way of doing functions
with many arguments.

> PS.  I see that Guido finally gave a (different) use case for bare * that 
> does make sense to me.

It's actually the same use case: I don't *want* callers to pass these
parameters positionally, to improve readability.

Regards,
Martin


More information about the Python-Dev mailing list