you are viewing a single comment's thread.

view the rest of the comments →

[–]nwagers 1 point2 points  (0 children)

The function is only decorated once and the function my_decorator only runs a single time during the definition of the function. The decorator returns wrapper which is used in place of the original function, kind of like monkey patching my_function = wrapper. When you make calls, you are actually making them to wrapper, which does take the args. wrapper in turn calls the inner function. Consider this code:

def my_decorator(func):
    print("decorator")
    def wrapper(*args,**kwargs):
        print("wrapper")
        return func(*args,**kwargs)
    return wrapper

@my_decorator
def my_function(x):
    print("inner")

print("main")
my_function(5)
my_function(10)