On Mon, Aug 17, 2009 at 7:03 PM, Julien Le Dem <julien.ledem@yahoo-inc.com> wrote:
Is there a way to get the function signature from a PyFunction object ?
I would like to know the number of parameters a function takes and their

Two slightly icky ways I know (both implemented deep in the bowls of Field's text editor):

1) eval "inspect.formatargspec(*inspect.getargspec(myfunction))" and parse the string that you get. This gets you keyword and variable arguments and their defaults.

2) crash right through the API:

int argCount = ((PyTableCode) myfunction.func_code).co_argcount;
String[] v = ((PyTableCode) myfunction.func_code).co_varnames;

Then stare at PyBaseCode.call to see if you can figure out all the corner cases. We use '1' in the case of CodeFlag.CO_VARARGS or CO_VARKEYWORDS or '2' otherwise.

I would be happy to hear other ideas, but this code is working fine for us.