How to get the formal args of a function object?

kj socyl at
Thu May 14 15:31:55 EDT 2009

Suppose that f is an object whose type is 'function'.

Is there a way to find out f's list of formal arguments?

The reason for this is that I'm trying to write a decorator and
I'd like the wrapper to be able to check the number of arguments
passed.  Specifically, I'd like the wrapper to look as shown below:

def _wrap(f):
    def wrapper(self, *params):
        n_expected = len(f.FORMAL_ARGS)
        n_received = len(params)
        if n_received is not n_expected:
            raise RuntimeError("Wrong number of arguments passed "
                               "to %s" % f.__name__)
        return self.send_jsonrpc_request(f.__name__, params)
    return wrapper

...but I'm missing something like the hypothetical attribute



NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.

More information about the Python-list mailing list