Guido van Rossum wrote: > On 4/19/06, Nick Coghlan <[EMAIL PROTECTED]> wrote: > >>Guido van Rossum wrote: >> >>>Here's a related but more complicated wish: define a function in such >>>a way that certain parameters *must* be passed as keywords, *without* >>>using *args or **kwds. This may require a new syntactic crutch. >> >>A single '*' could indicate that no additional positional arguments were >>permitted. >> >>def f(*, paramA, paramB=10): >> print paramA, paramB >> >>Here paramA and paramB can only be passed as keywords, and paramA *has* to be >>passed as it has no default. > > > I once considered and rejected this syntax since another logical > interpretation would be that any positional arguments are accepted but > *ignored*.
While I guess I can understand why that might be interpreted that way, such an interpretation also assume the feature is pretty worthless; why would you ignore the arguments, instead of just ignore the variable the arguments were put into? >>Utterly magical to anyone not already familiar with the use of *args, though. > > > But so would any other newly invented syntax, probably, so that > doesn't count heavily. > > Would *None be too bizarre? Hmm... def f(*(), paramA, paramB=10): *() would kind of imply you have to unpack the positional parameters into (), and of course the only thing that can be unpacked to () is (). Kind of building on the idea that f(*(a, b)) and f(a, b) are equivalent calls, even though in a signature *(a, b) isn't actually allowed (being pointless anyway). But while it has some logical meaning, I don't know if it reads particularly well; too many ()'s, and most people don't encounter empty tuples anyway, and probably don't think of signatures as packing and unpacking. * alone and *None read better to me. * by itself feels most like it is splitting the positional arguments from the keyword arguments: def write_text(s, *, font=None, size=None, color=None, ...): ... The primary use case I see is with a method that has lots of keyword arguments (4+), at which point no one is going to remember the order of the arguments, including people implementing functions with the same signature. With a lot of keyword arguments, **(font=None, size=None, ...) (noted in another message) doesn't feel as nice... though actually as I think about it, maybe that's not true, maybe it does look just as nice. -- Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com