Determining if a function is a method of a class within a decorator
jeremiah.dodds at gmail.com
Thu Jul 2 10:44:44 CEST 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.
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...
More information about the Python-list