> > 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. > > While a number of people have submitted possible use cases for this > feature, others have challenged the validity of such cases. > > At this point, I don't feel that the use cases for part 2 of the PEP are > as well-understood as the use cases for part 1. >
maybe those use cases can work without syntactic sugar. With only part 1, you can already add a manual check if you need: >>> def myfunction(a1, a2, *forbidden, kw1, kw2): ... assert forbidden is (), "myfunction() takes exactly 2 arguments" ... pass >>> If you want to have access to the function itself (to modify the signature), you can use a decorator: >>> @forbid('forbidden') >>> def myfunction(a1, a2, *forbidden, kw1, kw2): ... pass >>> (there can be a hook in the function object that @forbid will call, which would both fix the signature and add the runtime check) or, some time in the future, a typecheck: >>> @forbid_moreargs >>> def myfunction(a1, a2, *forbidden : Forbidden, kw1, kw2): ... pass >>> (where Forbidden is a marker object) As long as we have an agreed upon idiom, it is not really important if it takes on more line. Personnaly, I find any of those far more explicit that the lone start thinggy. Baptiste _______________________________________________ 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