Functools: functools.wraps
Understand how to use functools.wraps as a decorator to retain original function names and docstrings when applying decorators. This lesson helps you maintain proper function metadata for improved introspection and clearer API code.
We'll cover the following...
We'll cover the following...
Overview of wraps tool
There is a little known tool that we wanted to cover in this lesson. It
is called wraps and it too is a part of the functools module. We can use wraps as a decorator to fix docstrings and names of decorated functions.
Why does this matter? This sounds like a weird edge case at first, but if we are writing an API or any code that someone other than ourself will be using, then this could be important. The reason is that when we use Python’s introspection to figure ...