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

Nick Coghlan ncoghlan at gmail.com
Sun Apr 30 13:01:54 CEST 2006


Terry Reedy wrote:
> "Talin" <talin at acm.org> wrote in message news:4453B025.3080100 at acm.org...
>>     Now, suppose you wanted to have 'key' be a keyword-only argument.
> 
> Why?  Why not let the user type the additional argument(s) without the 
> parameter name?

Because for some functions (e.g. min()/max()) you want to use *args, but 
support some additional keyword arguments to tweak a few aspects of the 
operation (like providing a "key=x" option).

Currently, to support such options, you need to accept **kwds, then go poking 
around inside the dict manually. This PEP simply allows you to request that 
the interpreter do such poking around for you, rather than having to do it 
yourself at the start of the function.

I used to be a fan of the idea, but I'm now tending towards a -0, as I'm 
starting to think that wanting keyword-only arguments for a signature is a 
sign that the first argument to the function should have been an iterable, 
rather than accepting *args.

However, there are syntactic payoffs that currently favour using *args instead 
of accepting an iterable as the first argument to a function. I recently went 
into a lot more detail on that topic as part of the py3k discussion of set 
literals [1]. I'd like to turn that message into the core of a PEP eventually, 
but given the target would be Python 2.6 at the earliest, there are plenty of 
other things higher on my to-do list.

Cheers,
Nick.

[1]
http://mail.python.org/pipermail/python-3000/2006-April/001504.html

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list