In article <[EMAIL PROTECTED]>, "Talin" <[EMAIL PROTECTED]> wrote:
> (Note: PEPs in the 3xxx number range are intended for Python 3000, > however this particular PEP may be backported if there is support for > it.) > > PEP: 3102 > Title: Keyword-Only Arguments ... > Syntactically, the proposed changes are fairly simple. The first > change is to allow regular arguments to appear after a varargs > argument: > > def sortwords(*wordlist, case_sensitive=False): > ... > > This function accepts any number of positional arguments, and it > also accepts a keyword option called 'case_sensitive'. This > option will never be filled in by a positional argument, but > must be explicitly specified by name. The following is a 2nd syntactical change, and I strongly suggest listing it as such (since the first change can be made without this change): > Keyword-only arguments are not required to have a default value. > Since Python requires that all arguments be bound to a value, > and since the only way to bind a value to a keyword-only argument > is via keyword, such arguments are therefore 'required keyword' > arguments. Such arguments must be supplied by the caller, and > they must be supplied via keyword. ...making this the third syntactical change: > The second syntactical change is to allow the argument name to > be omitted for a varargs argument. The meaning of this is to > allow for keyword-only arguments for functions that would not > otherwise take a varargs argument: > > def compare(a, b, *, key=None): Personally, my feelings are: +1 on allowing keyword arguments after *args. I have long wanted this and feel it is: - very useful (the alternative of abusing **kargs is ugly and doesn't support introspection) - an obvious and clear extension of current notation - removes an awkward limitation of current notation -1 on allowing keywords without values because: - if it is added, then it means something like the last change is required, and as I say next, I don't like it - why bother? it just makes work for the caller -1 on the use of * to mean a separator between positional args and keyword-only args because: - I think proposed syntax is confusing (there are more arguments in the argument list than the function accepts; yecch!!!) and hard to read - I don't think the added functionality is important enough to justify the awkward notation If folks are desperate enough for this last feature then please at least find a clearer notation. For example: def compare(a, b | key=None): but personally I'd rather skip it. Now if somebody could figure out a natural notation for boolean flags, *that'd* be useful (where the presence, absence or explicit negation of a keyword is all that is required to enable or disable a feature). -- Russell -- http://mail.python.org/mailman/listinfo/python-list