Rodrigo 🐍🚀
Rodrigo 🐍🚀

@mathsppblog

4 Tweets 1 reads Mar 18, 2023
There is one thing you should probably do EVERY TIME you define a Python 🐍 decorator.
And that is: use the `functools.wraps` decorator!
Why?
Look at the example below.
I defined a simple decorator and then applied it to a function of mine.
My function loses important meta information:
The job of `functools.wraps` is to preserve this meta information.
It preserves things like the function name and the docstring.
How do you do that, though?
Just decorate your wrapper function!
If you want to learn more about decorators, I will be giving a remote workshop on this topic.
The workshop will be Saturday, 3rd December, 4pm UTC.
Only 30 spots available.
gum.co

Loading suggestions...