Determining if a function is a method of a class within a decorator

Jeremiah Dodds jeremiah.dodds at gmail.com
Thu Jul 2 04:44:44 EDT 2009


On Wed, Jul 1, 2009 at 2:14 AM, David Hirschfield <davidh at ilm.com> wrote:

>  Unfortunately that still requires two separate decorators, when I was
> hoping there was a way to determine if I was handed a function or method
> from within the same decorator.
>
> Seems like there really isn't, so two decorators is the way to go.
> Thanks,
> -David
>
>
This is a really horrible idea, but it may work:

If you can rely on your code using the word "self", you could use the
inspect module to look at the arguments of the function being decorated, and
dispatch based on that. The idea itself feels extremely dirty though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090702/cc45876a/attachment.html>


More information about the Python-list mailing list