A decorator replaces the function object; the syntax is essentially executed as:
def hello():
return "hello world"
hello = makeHtmlTag(tag="i", css_class="italic_css")(hello)
makeHtmlTag()
returns the real_decorator()
function, which is called with hello
as the argument, and it in turn returns wrapped()
.
So, after the decorator has been called, hello
is now bound to the wrapped()
function the real_decorator()
nested function returned.
If you replace def wrapped()
.. return wrapped
with a return
statement returning just a string, then hello
is now bound to that string and is not a function anymore. You cannot call a string object, leading to your TypeError
exception.