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

Jason Orendorff jason.orendorff at gmail.com
Mon May 1 15:14:38 CEST 2006


On 4/30/06, Edward Loper <edloper at gradient.cis.upenn.edu> wrote
(referring to keyword-only arguments):
> I see two possible reasons:
>
>    - A function's author believes that calls to the function will be
>      easier to read if certain parameters are passed by name, rather
>      than positionally; and they want to enforce that calling
>      convention on their users.  This seems to me to go against the
>      "consenting adults" principle.
>
>    - A function's author believes they might change the signature in the
>      future to accept new positional arguments, and they will want to put
>      them before the args that they declare keyword-only.
>
> Both of these motivations seem fairly weak.  Certainly, neither seems to
> warrant a significant change to function definition syntax.

I disagree.  I think the use cases are more significant than you
suggest, and the proposed change less significant.

Readability and future-compatibility are key factors in API design. 
How well a language supports them determines how sweet its libraries
can be.

Even relatively simple high-level functions often have lots of clearly
inessential "options". When I design this kind of function, I often
wish for keyword-only arguments.  path.py's write_lines() is an
example.

In fact... it feels as though I've seen "keyword-only" arguments in a
few places in the stdlib.  Am I imagining this?

Btw, I don't think the term "consenting adults" applies.  To me, that
refers to the agreeable state of affairs where you, the programmer
about to do something dangerous, know it's dangerous and indicate your
consent somehow in your source code, e.g. by typing an underscore. 
That underscore sends a warning.  It tells you to think twice.  It
tells you the blame is all yours if this doesn't work.  It makes
consent explicit (both mentally and syntactically).

I'm +1 on the use cases but -0 on the PEP.  The proposed syntax isn't
clear; I think I want a new 'explicit' keyword or something.  (Like
that'll happen.  Pfft.)

-j


More information about the Python-Dev mailing list