MemotivaFunctions and arguments

How do you preserve function metadata when writing a decorator?

Functions and arguments

Audio flashcard · 0:15

Nortren·

How do you preserve function metadata when writing a decorator?

0:15

When a decorator wraps a function, the wrapped function's name, docstring, and other metadata are replaced by those of the wrapper. The functools.wraps decorator, applied to the inner wrapper function, copies the original metadata. This is important for debugging and introspection.
docs.python.org