I have prepared some function decorator with default argument passed from decorator point of view:
def decorator_wraper(max_repeating=20)
def decorator(function):
def wrap_function(*args, **kwargs):
print(f"max_repeating = {max_repeating}")
repeat = 0
while repeat < max_repeating:
try:
return function(*args, **kwargs)
break
except Exception:
pass
repeat += 1
return wrap_function
return decorator
It works ok, so if some decorated function fails - decorator allows to repeat the function until success or repeat >= max_repeating.
But what if I will need to change the default max_repeating from decorated function point of view?
Here I have two decorated functions:
@decorator_wraper(5)
def decorate_me_with_argument(max_repeating=10):
print('decorate_me_with_argument')
@decorator_wraper()
def decorate_me_with_default():
print('decorate_me_with_default')
calling:
decorate_me_with_argument() # max_repeating should be 5 cause while decorating the function I have passed 5.
decorate_me_with_default() # max repeating should be 20 cause default for the decorator is 20.
And what I want to achieve:
decorate_me_with_argument(3) # max_repeating should be 3
decorate_me_with_default(8) # max repeating should be 8
Maybe is there any simple method to solve something like this?