PyPython · Lesson 12 of 14
Decorators & Functional Tools
A decorator is just a function that takes a function and returns a function. The @syntax is syntactic sugar. It looks magic; it is not magic. It is just clever use of the fact that functions are objects.
◆ Note
functools.wraps is not optional — without it, your decorated function loses its __name__ and __doc__, which breaks introspection, logging, and error messages. Always include it in every wrapper you write.
functools.wraps is not optional — without it, your decorated function loses its __name__ and __doc__, which breaks introspection, logging, and error messages. Always include it in every wrapper you write.