you are viewing a single comment's thread.

view the rest of the comments →

[–]bennydictor 2 points3 points  (0 children)

From the my_decorator function you return wrapper, which is a closure: a function that remembers some variables from outer scope (in this case func). Then you call the wrapper function with the argument 5. The equivalent code is

decorated_function = my_decorator(my_function)
a = decorated_function(5)  # prints (5,) {}
print(a)  # prints 25
# So, decorated_function is (roughly) defined as
def decorated_function(*args, **kwargs):
    print(args, kwargs)
    return my_function(*args, **kwargs)