import inspect


def str2type_name(str2type_function):
    """
    Return the function name of the function returned from
    str2type, or any function obtained by the type() operation.
    Useful when reporting conversion str-to-value errors.
    """
    s2t = str2type_function
    if "<type '" in str(s2t):
        name = str(s2t).split("'")[1]  # <type 'int'>
    elif inspect.isclass(s2t):
        name = s2t.__class__.__name__
    elif inspect.isfunction(s2t):
        name = s2t.__name__
    else:
        name = str(s2t)
    return name