[portland] introspecting method signatures

Jeff Schwaber freyley at gmail.com
Wed Oct 22 22:45:06 CEST 2008


Hey folks,

I'm trying to find a way to get method signatures at runtime, or pass
signatures straight through to an inside function. I'm basically
trying to redefine functions to do what they currently do but do
something else first. My current idea, stymied by signatures, is to
create closures wrapping the functions.

So something like this:

def foo(a, b):
  pass
def bar(b = None):
  pass

funclist = [foo, bar]
closurelist = []

for func in funclist:
  def closure():      # this should have the arguments for the func
      # do something
      func()              # so I can pass them in here
  closurelist.append(closure)

The closest I've found is func.func_code.co_varnames, which is a list
of variables in the signature, but it doesn't have default arguments
or mark any which are * or **. Anybody know the right way to do this,
or am I barking up the wrong tree? The # do something is what I'm
after.

Thanks,

Jeff


More information about the Portland mailing list