import inspect
from collections.abc import Callable
from typing import Any


def call_with_relevant_kwargs(func: Callable, /, **kwargs) -> Any:
    """Call a function with its named kwargs.

    If func accepts **kwargs, all arguments are passed.
    """
    sig = inspect.signature(func)
    params = sig.parameters

    accepts_kwargs: bool = any(p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values())
    if accepts_kwargs:
        return func(**kwargs)

    relevant = {k: v for k, v in kwargs.items() if k in sig.parameters}
    return func(**relevant)
