Why should every decorator use `functools.wraps`?
IntermediateConceptLanguage essentials & functions
Answer
Without it the wrapper replaces the original's __name__, __doc__, __module__, __qualname__ and signature metadata. Logs then say wrapper failed, help() shows nothing useful, click and FastAPI (which inspect signatures) break, and pytest fixtures or Flask routes collide because every view is named wrapper. @functools.wraps(fn) copies the metadata and sets __wrapped__ so tools can reach the original.
More on Language essentials & functions
Why is Python the default scripting language in so many DevOps teams, and where would you not use it?BeginnerWhat is the difference between mutable and immutable types? Give examples.BeginnerWhat does assignment do in Python, and how do shallow and deep copies differ?BeginnerExplain the mutable default argument bug and how to fix it.IntermediateWhat is the difference between `==` and `is`?BeginnerWhat values are "falsy" in Python, and why does it matter in scripts?Beginner