import functools


def update_upon_eval(fn, pbar, verbosity=1):
    """Decorate `fn` such that every time it is called, `pbar` is updated
    """

    @functools.wraps(fn)
    def new_fn(**kwargs):
        if verbosity >= 2:
            pbar.set_description(str(kwargs))
        result = fn(**kwargs)
        pbar.update()
        return result

    return new_fn