Repository: plotly/dash
File: dash/_callback.py (Python)

Code before:
        :param on_error:
            Function to call when the callback raises an exception. Receives the
            exception object as first argument. The callback_context can be used
            to access the original callback inputs, states and output.
        :param optional:
            Mark all dependencies as not required on the initial layout checks.
        :param hidden:
            Hide the callback from the devtools callbacks tab.
        :param api_endpoint:
            If provided, the callback will be available at the given API endpoint.
            This allows you to call the callback directly through HTTP requests
            instead of through the Dash front-end. The endpoint should be a string
            that starts with a forward slash (e.g. `/my_callback`).
            The endpoint is relative to the Dash app's base URL.
            Note that the endpoint will not appear in the list of registered
            callbacks in the Dash devtools.
    """

    background_spec = None

    config_prevent_initial_callbacks = _kwargs.pop(
        "config_prevent_initial_callbacks", False
    )
    callback_map = _kwargs.pop("callback_map", GLOBAL_CALLBACK_MAP)
    callback_list = _kwargs.pop("callback_list", GLOBAL_CALLBACK_LIST)
    callback_api_paths = _kwargs.pop("callback_api_paths", GLOBAL_API_PATHS)

    if background:
        background_spec: Any = {
            "interval": interval,
        }

        if manager:
            background_spec["manager"] = manager

        if progress:
            background_spec["progress"] = coerce_to_list(progress)
            validate_background_inputs(background_spec["progress"])

        if progress_default:
            background_spec["progressDefault"] = coerce_to_list(progress_default)

            if not len(background_spec["progress"]) == len(
                background_spec["progressDefault"]
            ):
                raise Exception(
                    "Progress and progress default needs to be of same length"
                )

        if cancel:
            cancel_inputs = coerce_to_list(cancel)

Review comment (performance):
Let's only have the global one, having two variables for the same functionality creates issue like #3419 and add complexity.

Code after:
        :param on_error:
            Function to call when the callback raises an exception. Receives the
            exception object as first argument. The callback_context can be used
            to access the original callback inputs, states and output.
        :param optional:
            Mark all dependencies as not required on the initial layout checks.
        :param hidden:
            Hide the callback from the devtools callbacks tab.
        :param api_endpoint:
            If provided, the callback will be available at the given API endpoint.
            This allows you to call the callback directly through HTTP requests
            instead of through the Dash front-end. The endpoint should be a string
            that starts with a forward slash (e.g. `/my_callback`).
            The endpoint is relative to the Dash app's base URL.
            Note that the endpoint will not appear in the list of registered
            callbacks in the Dash devtools.
    """

    background_spec = None

    config_prevent_initial_callbacks = _kwargs.pop(
        "config_prevent_initial_callbacks", False
    )
    callback_map = _kwargs.pop("callback_map", GLOBAL_CALLBACK_MAP)
    callback_list = _kwargs.pop("callback_list", GLOBAL_CALLBACK_LIST)

    if background:
        background_spec: Any = {
            "interval": interval,
        }

        if manager:
            background_spec["manager"] = manager

        if progress:
            background_spec["progress"] = coerce_to_list(progress)
            validate_background_inputs(background_spec["progress"])

        if progress_default:
            background_spec["progressDefault"] = coerce_to_list(progress_default)

            if not len(background_spec["progress"]) == len(
                background_spec["progressDefault"]
            ):
                raise Exception(
                    "Progress and progress default needs to be of same length"
                )

        if cancel:
            cancel_inputs = coerce_to_list(cancel)
            validate_background_inputs(cancel_inputs)