def function_to_str()

in nubia/internal/helpers.py [0:0]


def function_to_str(function, with_module=True, with_args=True):
    """
    Returns a nice string representation of a function
    """
    string = getattr(function, "__name__", str(function))
    if with_module:
        string = "{}.{}".format(function.__module__, string)
    if with_args:
        argspec = get_arg_spec(function)
        args_string = ", ".join(argspec.args)
        if argspec.varargs:
            args_string = "{}, *{}".format(args_string, argspec.varargs)
        if argspec.varkw:
            args_string = "{}, **{}".format(args_string, argspec.varkw)
        string = "{}({})".format(string, args_string)
    return string