Skip to content

funcs

Functions:

copy_func

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

Try copying a function.

Source code in jetpytools/utils/funcs.py
10
11
12
13
14
15
16
17
18
19
def copy_func(f: Callable[..., Any]) -> FunctionType:
    """Try copying a function."""

    try:
        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]
    except BaseException:
        return f  # 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
27
28
29
30
31
32
33
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