Skip to content

funcs

Functions:

copy_func

copy_func(f: Callable[..., Any]) -> FunctionType

Try copying a function.

Source code in jetpytools/utils/funcs.py
11
12
13
14
15
16
def copy_func(f: Callable[..., Any]) -> FunctionType:
    """Try copying a function."""
    g = FunctionType(f.__code__, f.__globals__, name=f.__name__, argdefs=f.__defaults__, closure=f.__closure__)
    g.__kwdefaults__ = f.__kwdefaults__
    g = update_wrapper(g, f)
    return g  # type: ignore[return-value]

erase_module

erase_module(func: F, modules: Sequence[str] | None = None) -> F

Delete the module of the function.

Source code in jetpytools/utils/funcs.py
24
25
26
27
28
29
30
def erase_module[F: Callable[..., Any]](func: F, modules: Sequence[str] | None = None) -> F:
    """Delete the __module__ of the function."""

    if isinstance(func, _HasModule) and (modules is None or func.__module__ in modules):
        func.__module__ = ""

    return func