import typing
import inspect


def tidy_fn_call(fn: typing.Callable, args: typing.Iterable, kwargs: dict):
    """
    Put args to kwargs if they matches.

    This works like a function call parser.

    Parameters
    ----------
    fn : typing.Callable
        The function to be called (it won't be called).
    args : typing.Iterable
        The positional arguments.
    kwargs : dict
        The keyword arguments.

    Returns
    -------
    tuple
        args, kwargs
    """
    # we have to assign the stuff in `args` to `kwargs`
    args = list(args)
    params = inspect.signature(fn).parameters
    for name, param in params.items():
        if not any(args):
            break  # no more pos args to process
        if name in kwargs:
            continue  # already specified in kws
        # confirmed
        kwargs[name] = args.pop()
    # 1. no one wants None stuff
    # 2. cvt obj to dict
    kwargs = {
        k: v  # if isinstance(v, (str, list, dict)) else to_dict(v)
        for k, v in kwargs.items()
        if v
    }
    return args, kwargs