I have a @on_event
decorator that registers function as a callback for a specified event :
@on_event('MY_EVENT')
def on_event_triggers(*a, **k):
print('Event triggered')
But, I want my decorator to work on "global" functions (as above) and on class functions:
class MyModule(Module):
@on_event('MY_EVENT')
def on_event_triggered(self, *a, **k):
print('Event triggered in a method')
Of course, the self
argument will be passed correctly (and determined by some piece of code I don't show here). However, for this to work I have to be able to know if the function passed to my decorator is a method or a global function.
I'm using Python 3.3.