I have added my decorator to instance methods of the class:
def method_decorator(func):
def wrap(self, *args, **kwargs):
print("Start to perform " + func.__name__)
try:
func(self, *args, **kwargs)
finally:
print("Finish to perform " + func.__name__ + "\n")
# make func calling without decorator
wrap.no_decorator = func
return wrap
class Simulator:
def __init__(self):
self.busy = False
@method_decorator
def get_smth(self, text):
print('test')
...
Simulator().get_smth('text') -> works
But how can I call get_smth
without decorator involving?
You can see in the code that I tried to attach origin func
to result from decorator method (as suggested at one of the SO answers), but it doesn't work.
Simulator().get_smth.no_decorator('text') -> requires parameter for `get_smth`
Is there a way to achieve this with Python 3? Also, I would like to call the undecorated function from other instance methods of this class