[Types-sig] Keyword arg declarations

David Ascher da@ski.org
Fri, 17 Dec 1999 10:53:18 -0800


From: "Guido van Rossum" <guido@CNRI.Reston.VA.US>


> I just realized that Tim's decl syntax that's currently being bandied
> around doesn't declare the names of arguments.  That's fine for a
> language like C, but in Python, any argument with a name (*args
> excluded) can be used as a keyword argument.

This brings to mind a point which may or may not be relevant.  Sometimes
Python users use some tricks to do 'deferred' type checking and other
argument manipulation, because the syntax doesn't allow one to specify the
interface which one needs.

An example of such a signature is familiar to all is the signature for
range().  The docstring for range reads:

range([start,] stop[, step]) -> list of integers

which is not expressible with the current syntax.  A Python version of range
would have to do, much like NumPy's arange does,

def range(start, stop=None, step=1):
    if (stop == None):
        stop = start
        start = 0

Now, the builtin typechecker can of course be told about __builtin__.range's
signature peculiarities, but is there any way we can address the more
general problem?  Or is it, as I suspect, rare enough that one can ignore
it?

> (Note that not all builtins support keyword arguments; in fact most
> don't.)

And a shame it is, IMO.  Would it make sense to consider for 2.0 a mechanism
which allows keyword arguments almost by default?  That way I could do

pickle.dump(object=foo, file=myfile)

and never have to worry about which came first...

--david