import importlib


def import_stringified_func(funcstring):
    """
    Import a string that represents a module and function, e.g. {module}.{funcname}.

    Given a function f, import_stringified_func(stringify_func(f)) will return the same function.
    :param funcstring: String to try to import
    :return: callable
    """
    if not isinstance(funcstring, str):
        raise TypeError("Argument must be a string")

    modulestring, funcname = funcstring.rsplit(".", 1)

    mod = importlib.import_module(modulestring)

    func = getattr(mod, funcname)
    return func