Built-in functions and keyword arguments

J. Clifford Dyer jcd at sdf.lonestar.org
Mon Oct 29 19:09:37 CET 2007

On Mon, Oct 29, 2007 at 02:27:50PM +0000, Duncan Booth wrote regarding Re: Built-in functions and keyword arguments:
> Bruno Desthuilliers <bruno.42.desthuilliers at wtf.websiteburo.oops.com> 
> wrote:
> > In the second case, the name of the argument *is* 'object'. Which is not 
> > the case for the builtin len (which, fwiw, has type 
> > 'builtin_function_or_method', not 'function', so inspect.getargspec 
> > couldn't tell me more).
> > 
> ><ot>
> > While we're at it, you should avoid using builtin's names for 
> > identifiers - here, using 'object' as the arg name shadows the builtin 
> > 'object' class).
> ></ot>
> I think you are being a little bit unfair here: help(len) says:
> len(...)
>     len(object) -> integer
>     Return the number of items of a sequence or mapping.
> which implies that the argument to len has the name 'object' (although in 
> fact it doesn't have a name). The OP was simply asking about the difference 
> in calling conventions, not proposing to write code using 'object' as the 
> argument name.

Hmm....  To my mind, that just implies that the *type* of the expected input is an object.  Just like the "-> integer" tells you that the type of the output is an integer.  If the documentation read "len(s=object) -> integer", then I would expect a keyword argument s typed as an object.

Now that might also be misleading, as not all objects have a length (integers, for example raise a TypeError).  But the documentation has to say something, which doesn't imply that every argument has to be a keyword.


More information about the Python-list mailing list