In the previous cases, we decorated functions which took in no arguments. Let's modify our functions now so that we can accept arguments.
As you can see, we receive an error that says wrapper() takes 0 positional arguments but 1 was given
. This happens as our decorator does not currently support arguments. We can change this by accepting name
as a parameter within wrapper()
.
We could also make the decorator more generic by accepting variable arguments i.e *args
and **kwargs
.
Our code here allows wrapper()
to accept any number of positional and keyword arguments and forward them to the function which is being decorated.