I have a decorator, and in that decorator I want to check if the decorated function has an argument with the name query
. If it exists I want to detect its position in *args
like this: args[1]
. I want to perform this in wrapper function. I want to do something like this:
def some_decorator(func):
@wraps(func)
def wrapper_func(*args, **kwargs):
ind = 0
query = ''
for arg in args:
if arg.__name__ == 'query'
query = 'Found'
break
ind +=1
if query == 'Found':
query = args[ind]
return wrapper_func
For clarity, I use it like this:
@some_decorator
def find_all(self, some_arg, query=None):
pass
The thing is, I use the decorator also for other functions, with different signatures that may or may not have query
argument. I hope this clarifies things.