def hpcwrap()

in src/hpc/autoscale/codeanalysis.py [0:0]


def hpcwrap(function: Callable) -> Callable:

    if not RUNTIME_TYPE_CHECKING:
        return function

    if "all" in TRACE_FUNCTIONS or function.__name__ in TRACE_FUNCTIONS:

        def apitraceall(func: Callable) -> Callable:
            return apitrace(func, repro_level=True, fine_level=False, trace_level=True)

    else:

        def apitraceall(func: Callable) -> Callable:
            return func

    if function.__name__ in WHITELIST_FUNCTIONS_TYPES:
        # disable type checking, often because it uses subscripted types, sadly.
        typechecked_func = function
    else:
        typechecked_func = typecheck_function(function, apitraceall)

    def hpcwrapper(*args: Any, **kwargs: Any) -> Optional[Any]:
        if function.__name__ in WHITELIST_FUNCTIONS_TYPES:
            if not hasattr(hpcwrapper, "hpcwarned"):
                setattr(hpcwrapper, "hpcwarned", True)
                logging.warning(
                    "Runtime type checking is disabled for %s", function.__name__
                )
        return typechecked_func(*args, **kwargs)

    return hpcwrapper