Re: [Q] Number of of arguments of a funcobject?

Guido.van.Rossum@cwi.nl
Tue, 23 Aug 1994 00:45:48 +0200

> Suppose I want to write something like
>
> static object* foo_create(object*, object* args)
> {
> object* function;
> if (!getargs(args, "O", &function))
> return NULL;
> if (!is_funcobject(function)) {
> err_setstr(TypeError, "function expected as argument");
> return NULL;
> }
>
> ..........
>
> Now, I need the number of input and output arguments of function
> eg. 2 and 3 for
>
> def f(x,y):
> return (x-y,x,y);
>
> How can I get them in my C code? I tried it with "getfuncargstuff"
> but this didn't work. Can somebody help me?

Hmm, you can't do that. You have to call the function with the number
of arguments you see fit and if that isn't the number that the
function expects, you get an exception. The getfuncargstuff()
function is only meant to handle default arguments.

Why exactly would you want to do this, other than early error checking
(which is not the Pythonic way of doing things anyway)?

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
<URL:http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>