CKTIS / Python
functools.update_wrapper
Copies selected metadata from the wrapped callable and exposes it through the wrapper’s original-function attribute.
Version: Python 3.14; repository image, production runtime not attested
Syntax
functools.update_wrapper(wrapper, wrapped, assigned=functools.WRAPPER_ASSIGNMENTS, updated=functools.WRAPPER_UPDATES)Copies selected metadata from the wrapped callable and exposes it through the wrapper’s original-function attribute.
The wrapper keeps its own executable behavior after the metadata update.
Mutate and return the wrapper. assigned attributes are copied from wrapped, while updated attributes (by default __dict__) are merged into their wrapper counterparts. The __wrapped__ reference points to the immediately wrapped callable. Execution still uses proxy's body; after copying the name source, proxy(3) yields 8 and the original yields 4. Since 3.12, update_wrapper and the wraps decorator copy the generic function's __type_params__ by default.
from functools import update_wrapper
def origin(x): return x+1
origin.tag = "v1"
def proxy(x): return 2*origin(x)
assert update_wrapper(proxy, origin) is proxy
assert proxy.__name__ == "origin" and proxy.tag == "v1" and proxy.__wrapped__ is origin
assert proxy(3) == 8 and proxy.__wrapped__(3) == 4
from functools import wraps
def ident[T](x: T) -> T: return x
def proxy2(*args): return ident(*args)
update_wrapper(proxy2, ident)
@wraps(ident)
def proxy3(*args): return ident(*args)
assert proxy2.__type_params__ is proxy3.__type_params__ is ident.__type_params__
Examples
import functools
def source(n): return n + 1
def proxy(n): return 2 * source(n)
functools.update_wrapper(proxy, source)
print(proxy.__name__, proxy(3), proxy.__wrapped__(3))
Result
source 8 4
Mutate and return the wrapper. assigned attributes are copied from wrapped, while updated attributes (by default `__dict__`) are merged into their wrapper counterparts. The `__wrapped__` reference points to the immediately wrapped callable. Execution still uses proxy's body; after copying the name source, proxy(3) yields 8 and the original yields 4. Since 3.12, update_wrapper and the wraps decorator copy the generic function's `__type_params__` by default.