Let's suppose I have a simple function returning its own name
def foo():
print(foo.__name__)
Of course the output when calling is foo
.
However, if we now decorate that function with a decorator like this:
def dec(func):
print(dec.__name__)
def wrapper(*args):
print(wrapper.__name__)
return func(*args)
return wrapper
@dec
def foo():
print(foo.__name__)
foo()
We get
dec
wrapper
wrapper
Why is the name of the inner function called here?
func(*args)
is specifically called, shouldn't it be really the function's name among with dec wrapper
?