Functional Functions

functools.wraps()

Create a decorator applying update_wrapper to a wrapper function. Preserving metadata and __wrapped__ supports introspection.

Formal Syntax & Structure

python syntaxpython
functools.wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)

Parameters & Attributes

NameTypeDescription
wrappedcallableOriginal callable whose metadata is copied.
assignedtuple[str, ...]Attribute names to assign from the wrapped object.
updatedtuple[str, ...]Attribute names whose mappings are updated.

Return Value

callable

The callable result described above.

Working Example

Example Snippetpython
import functoolsdef double(x): return x*2@functools.wraps(double)def wrapper(x): return double(x)print((wrapper.__name__,wrapper(3)))
Python Reference