# -*- encoding: utf-8 -*-

from typing import Callable
from typing import List
from typing import Any


class KeywordArgumentsFromArguments(object):
    def __init__(self, *kwargs_changes: List[str]):
        for oldkw in kwargs_changes:
            assert isinstance(oldkw, str) or oldkw is None
        self.kwargs_changes = kwargs_changes

    def __call__(self, c):
        return KeywordArgumentsFromArgumentsConfigured(c, *self.kwargs_changes)


class KeywordArgumentsFromArgumentsConfigured(object):  # Don't instantiate this class manually
    def __init__(self, clb: Callable, *kwargs_changes: List[str]):
        self.kwargs_changes = kwargs_changes
        self.callback = clb
    
    def __call__(self, *args, **kwargs):
        newkwargs = kwargs.copy()
        for i, kw in enumerate(self.kwargs_changes):
            if kw is not None:
                newkwargs[kw] = args[i]
        return self.callback(**newkwargs)