Arnaud Delobelle wrote: > > On Feb 14, 11:13 pm, "Guido van Rossum" <[EMAIL PROTECTED]> wrote: >> On Thu, Feb 14, 2008 at 2:48 PM, Raymond Hettinger <[EMAIL PROTECTED]> wrote: >>> I've been exercising the new keyword-only arguments syntax. It is >>> absolutely wonderful. I'm amazed at how many long standing problems it >>> solves elegantly. >> Agreed. Now can you come up with a syntax for positional-only >> arguments? So far everybody has failed at that, and there are some use >> cases where it's useful too. > > The idea in PEP 3102 is that *args gobbles up all remaining positional > arguments, hence what comes after can only be interpreted as > keyword-only arguments. This is extended to allowing * on its own. > > e.g. f(*, z, t=2) > => z, t are keyword-only > > Following the same train of thought, **kwargs gobbles up all remaining > keyword arguments, hence what comes after can only interpreted as > positional-only arguments. Then one could extend it to allowing ** on > its own. > > e.g. f(**, x, y=1) > => x, y are positional-only > > Now, how do keyword-only arguments fit in? Say x, y=1 are > positional-only and z, t=2 are keyword-only. One could have: > > f(**, x, y=1, *, z, t=2) > > The general cases could look like > > f(x, y=1, *args, z, t=2, **kwargs): > => x, y are hybrid > => args: all remaining positional arguments > => z, t are keyword-only > => kwargs: all remaining keyword arguments > > f(**kwargs, x, y=1, *args, z, t=2): > => x, y are positional-only > => args: all remaining positional arguments > => z, t are keyword-only > => kwargs: all remaining keyword arguments > > 'args' and 'kwargs' are optional in both cases. If 'kwargs' is present > in the second version, it is a bit strange as it usually only appears > at the end. Alternatively, only '**' could be allowed at the start > and if needed '**kwargs' would come at the end: > > f(**, x, y=1, *args, z, t=2, **kwargs) > > Note that this syntax doesn't allow for positional-only and hybrid > arguments to coexist. But this is nice IMHO, as it seems to me that > it would only create confusion. > > Unconvincingly yours,
Well, that is certainly a logical continuation of the train of thought behind the 'single *' syntax. I'd be curious to know which parts of 3102 people are finding most useful. You see, the itch that I was originally attempting to scratch concerned just the narrow use case of combining a 'varargs' function with optional keywords. I've seen/written a lot of code where you have a function that takes a list of arguments, with a couple of optional keywords that control how that list is handled, and 3102 was intended to make that case much easier to handle. I was never all that interested in 'forcing' some of the arguments to a non-varargs function to be specified by keyword. I am perfectly comfortable with the idea that the caller always gets to choose whether to pass something positionally or via keyword, and limiting the caller's choice seems vaguely unpythonic to me. However, I included that part in the PEP based on the feedback from here. In any case, limiting arguments to being specified by keyword-only or positional-only was not part of my original 'itch', and I am curious as to what are the use cases for it that people are envisioning. > -- > Arnaud > > _______________________________________________ > Python-3000 mailing list > [email protected] > http://mail.python.org/mailman/listinfo/python-3000 > Unsubscribe: > http://mail.python.org/mailman/options/python-3000/talin%40acm.org > _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
