Aug-27-2019, 08:05 AM
(Aug-26-2019, 07:31 PM)Skaperen Wrote: so what does @my_decorator really do?It's not like the web are lacking info about decorators if you search
First hit google Primer on Python Decorators.
In my example with
@make_bold
,if take away all the magic of @
.It's just functions
foo
get passed to make_bold
function.make_bold
return new_func
which added stuff to foo
function. def make_bold(fn): '''Do not need to see me''' def new_func(): return f"<b>{fn()}</b>" return new_func def foo(): return 'python-forum' make_bold = make_bold(foo) # The cooler way is @make_boldThe same results.
>>> make_bold() '<b>python-forum</b>'
Quote:are decorators always functions? what if some arbitrary function is used?No,look at link given.
It's also used in Data Classes.
If you really need to look at source before use Click,then it's all open Click GitHub