[Python-Dev] PEP 3102: Keyword-only arguments
Russell E. Owen
rowen at cesmail.net
Tue May 2 22:22:45 CEST 2006
In article
<ca471dc20605020744m333c855cqbf9016340ea5d699 at mail.gmail.com>,
"Guido van Rossum" <guido at python.org> wrote:
> On 5/2/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> > Terry Reedy wrote:
> >
> > > my way to call your example (given the data in separate variables):
> > > make_person(name, age, phone, location)
> > > your way:
> > > make_person(name=name, age=age, phone=phone, location = location)
> >
> > For situations like that, I've sometimes thought
> > it would be useful to be able to say something like
> >
> > make_person(=name, =age, =phone, =location)
>
> And even with Terry's use case quoted I can't make out what you meant
> that to do.
I'm pretty sure he wants it to mean:
make_person(name=name, age=age, phone=phone, location=location).
In other words it's a shortcut to avoid needless repetition.
Personally I'd like some way to do that, but the initial "=" is pretty
startling at first glance. Not that I have a better suggestion.
As far as the rest of the thread goes (and I may be late to the party on
this), I personally would *love* to be able to write:
def func(arg0, arg1, *args, key1=def1)
and force key1 to be specified by name. I've coded this before using
**kargs for the keyword-only args, but I'd much rather be able to list
them in the def (making it more self-documenting).
But that's as far as I'd take it.
I don't see the point to keyword-only arguments that do not have default
values. And I don't think it's worth the potential confusion to allow
keyword-only args after a fixed # of positional args. The proposed
syntax reads like exactly the wrong thing to me; "|" as a separator
might do if one is desperate enough for this feature, i.e.:
def foo(arg0, arg1 | karg=None):
-- Russell
More information about the Python-Dev
mailing list