def _replace_value_in_saved_args(
    replace_key: str,
    replace_value: Any,
    args: tuple[Any, ...],
    kwargs: dict[str, Any],
    default_kwargs: dict[str, Any],
    arg_names: tuple[str, ...],
) -> tuple[bool, tuple[Any, ...], dict[str, Any]]:
    """Tries to replace an argument value in a saved list of args and kwargs.

    Returns a tuple indicating success of the operation and modified saved args and kwargs

    """

    if replace_key in arg_names:
        replace_index = arg_names.index(replace_key)
        args = args[:replace_index] + (replace_value,) + args[replace_index + 1 :]
        return True, args, kwargs
    if replace_key in kwargs or replace_key in default_kwargs:
        kwargs[replace_key] = replace_value
        return True, args, kwargs

    return False, args, kwargs
Tries to replace an argument value in a saved list of args and kwargs.

    Returns a tuple indicating success of the operation and modified saved args and kwargs

    
src/lightning/fabric/utilities/data.py