def upper(f):
@wrap
def uppercase(*args, **kargs):
a,b = f(*args, **kargs)
return a.upper(), b.upper()
return uppercase
A decorator in Python
@foo
def bar(...): ...
is just equivalent to
def bar(...): ...
bar = foo(bar)
You want to get the effect of
@wrap
@upper
def hello(): ....
i.e.
hello = wrap(upper(hello))
so the wrap
should be called on the return value of upper
:
def upper_with_wrap(f):
def uppercase(...): ...
return wrap(uppercase)
which is also equivalent to applying the decorator on that function:
def upper_with_wrap(f):
@wrap
def uppercase(...): ...
# ^ equivalent to 'uppercase = wrap(uppercase)'
return uppercase