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

Terry Reedy tjreedy at udel.edu
Mon May 1 20:07:16 CEST 2006


"Guido van Rossum" <guido at python.org> wrote in message 
news:ca471dc20605010728g2742bd01m4b4b284c15eabb18 at mail.gmail.com...

> A function/method could have one argument that is obviously needed and
> a whole slew of options that few people care about. For most people,
> the signature they know is foo(arg). It would be nice if all the
> options were required to be written as keyword arguments, so the
> reader will not have to guess what foo(arg, True) means.

Ok, this stimulates an old memory of written IBM JCL statements something 
like

DD FILENAME,,,,,2,,HOP

where you had to carefully count commas to correctly write and later read 
which defaulted options were being overridden.

dd(filename, unit=2, meth = 'hop') is much nicer.

So it seems to me now that '*, name1 = def1, name2=def2, ...' in the 
signature is a really a substitute for and usually an improvement upon 
(easier to write, read, and programmaticly extract) '**names' in the 
signature followed by
  name1 = names.get('name1', def1)
  name2 = names.get('name2', def2)
  ...
  (with the semantic difference being when defs are calculated)

(But I still don't quite see why one would require that args for required, 
non-defaulted param be passed by name instead of position ;-).

As something of an aside, the use of 'keyword' to describe arguments passed 
by name instead of position conflicts with and even contradicts the Ref Man 
definition of keyword as an identifier, with a reserved use, that cannot be 
used as a normal identifier.  The parameter names used to pass an argument 
by name are normal identifiers and cannot be keywords in the other sense of 
the word.  (Yes, I understand that this is usual CS usage, but Python docs 
can be more careful.)  So I would like to see the name of this PEP changed 
to 'Name-only arguments'

Terry Jan Reedy





More information about the Python-Dev mailing list