[portland] introspecting method signatures

Jesse Hallett hallettj at gmail.com
Wed Oct 22 23:09:17 CEST 2008



I found this link with code for aliasing methods. You can probably alias the 
original method, then override the original method name with a new method, 
and call the aliased method from the new method.

http://waimangu.typepad.com/notepad/2006/12/usrbinenv_pytho.html

I haven't tried the code though; so I can't guarantee that it works.

On Oct 22, 2008 1:45 PM, "Jeff Schwaber" <freyley at gmail.com> wrote:

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
_______________________________________________
Portland mailing list
Portland at python.org
http://mail.python.org/mailman/listinfo/portland

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/portland/attachments/20081022/690acd76/attachment.htm>


More information about the Portland mailing list