def apply_function(f, *args, **kwargs):
    """ Apply a function or staticmethod/classmethod to the given arguments.
    """
    if callable(f):
        return f(*args, **kwargs)
    elif len(args) and hasattr(f, '__get__'):
        # support staticmethod/classmethod
        return f.__get__(None, args[0])(*args, **kwargs)
    else:
        assert False, "expected a function or staticmethod/classmethod"