In Python I know a little about decorators. In my poor understanding a decorated funtion declaration returns whatever the decorator function constructs with the original function (most reasonably this should be a callable):
def deco(func):
def func_wrapper(name):
return func(name)+", how are you?"
return func_wrapper
@deco
def foo(name):
return "Hello "+name
print(foo("Michael"))
This gives:
Hello Michael, how are you?
But what if a decorator is specified along with an argument:
def deco2(info):
def info_decorator(func):
def func_wrapper(name):
return func(name) + info
return func_wrapper
return info_decorator
@deco2(", how are you?")
def foo2(name):
return "Hello "+name
print(foo2("Regina"))
giving
Hello Regina, how are you?
What is the "rule" for handling this decorator?
It seems, that instead of returning foo2 Python first calls deco2 with the given arg, and assumes, that this call first constructs a factory for a decorator, which then acts like before with foo2 passed to it in order to return the final wrapper. However, in this case there is one additional "layer" involved (three defs instead of two), which makes it hard for me, to identify the general rule.