[portland] introspecting method signatures

Jeff Schwaber freyley at gmail.com
Thu Oct 23 00:06:00 CEST 2008


On Wed, Oct 22, 2008 at 2:09 PM, Jesse Hallett <hallettj at gmail.com> wrote:
>
>
> 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.

Yeah, I'm not sure exactly why it's working and other things I've
tried aren't, but that looks like what I'm trying to do.

Decorators, as John Hampton suggested, may also be a good choice,
because they're pretty clear syntax.

Thanks,

Jeff

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


More information about the Portland mailing list