import types
import typing


def temp_fn_argument_extractor(
        mod: types.ModuleType,
        mod_attr: str,
) -> typing.Iterator[typing.List[typing.Tuple[list, dict]]]:
    """
    Temporarily intercept a function, so it's arguments can be extracted.
    The context manager gives us a list where each item is a tuple of
    arguments & keywords, stored each time the function was called.
    """
    args_collected = []
    real_fn = getattr(mod, mod_attr)

    def wrap_fn(*args, **kw):
        args_collected.append((args, kw))
        return real_fn(*args, **kw)
    setattr(mod, mod_attr, wrap_fn)
    try:
        yield args_collected
    finally:
        setattr(mod, mod_attr, real_fn)