The question is not stated very clearly, but I would assume that those two functions are in some class.
The problem is that you create a wrapper inside the class. Your wrapper check_if_logged
expects two arguments self
and function
. When you use it as wrapper @
you give only one argument to the function check_if_logged
(this argument is to_do_login_erp
). It doesn’t get the self
from the class, even though it is defined there. That is why you need to create wrappers outside the class.
One other thing that might come up later: your function
needs to be returned and not called (so not function()
). The wrapper looks normally like this:
def check_if_logged(function):
def wrapper():
check_something()
return function
return wrapper()
For your purposes I would not use the wrapper, and just directly make a check_if_logged in the function I want to call, because you as well want to use some properties or functions of your class to check if you are logged.
Hope this could help.
solved Decorator function [closed]