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
| Name | Type | Description |
|---|---|---|
| wrapped | callable | Original callable whose metadata is copied. |
| assigned | tuple[str, ...] | Attribute names to assign from the wrapped object. |
| updated | tuple[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)))