def adder(): n = 0 def add(): nonlocal n n += 1 return n return add def retry(n: int = 5): def deco(f): def inner(*args, **kwargs): for _ in range(n): f(*args, **kwargs) return inner return deco # @retry(5) def foo(): print("Hello world!") foo = (retry(5))(foo) @retry(15) def bar(): print("Bar")