[Python-ideas] keyword arguments everywhere (stdlib) - issue8706

Ron Adam ron3200 at gmail.com
Mon Mar 5 07:55:37 CET 2012

On Mon, 2012-03-05 at 10:31 +1000, Nick Coghlan wrote:

> So, *if* syntactic support for positional-only arguments were added, I
> think Guido's syntax would be the way to do it. However, now that I've
> realised the "arbitrary keyword arguments" problem can be solved
> fairly cleanly by a helper function that binds the positional
> arguments, I'm more inclined to just leave it alone and tell people to
> just accept *args and process it that way.

Yeah, I think I agree with that for now.  I feel signatures are already
pretty complex.  If we found a solution that worked while simplifying or
merging some of that complexity in a nice way, I'd be +1.

Your suggested syntax was leaning in that direction I think.  I liked
that there was a possibly a clearer separation between positional
arguments and keywords arguments.  

If you look at the C code that parses signatures, it's not simple or
straight forward.  It's not easy to write a python function that maps
(*args, **kwds) to a signature in the same way.  I tried it to test out
some ideas a while back.

What makes it difficult is some of the "*args" values can be keyword
arguments assigned by position.  Or some values in "**kwds" values may
be positional arguments assigned by name.  I think the order not being
preserved in kwds was also a factor.

While in the simple cases, it's fairly easy to mentally parse a
signature, the mental slope gets steeper as you start to combine the
different concepts into one signature.  Maybe it's easy for those who do
it every day, but not as easy for those doing it less often, or for
those who are just beginning to learn python. 

> OTOH, having a docs-friendly syntax, and better programmatic
> introspection for the cases where it does come up would be nice,
> too...

When I was looking at your syntax I was thinking of it like this...

   def foo(*(a, b=2)->args, **(c=3)->kwds):
       return args, kwds

Which would map the positional only arguments to args, and the rest to
kwds and include the default values as well.  But that's a different

That wouldn't be friendly to duck typing because functions in the front
of the chain should be not care what the signature of the function at
the end of the chain will be.  It would be limited to functions (ducks)
who's signatures are compatible with each other.

The (*args, **kwds) signature only corresponds to positional and
keywords arguments in the simple cases where no positional (only)
argument has a default value, and no keyword arguments are assigned by

As far as better docs-friendly syntax, and introspection are concerned,
I think we will need a signature object that can be introspected.  It
also might be helpful in evaluating ideas like these.



More information about the Python-ideas mailing list