import traceback


def exception_to_message(exception):
    """
    Given an exception 3-tuple as returned by run_transform(), returns
    a string formatted as Python would have formatted it.

    This is a convenience function for handling the somewhat odd
    exception info returned by run_transform().
    """
    # trace is a list produced by traceback.extract_tb().
    type_, value, trace = exception
    trace = traceback.format_list(trace)

    # We format the exception just like Python would.
    trace = "Traceback (most recent call last):\n" + "\n".join(trace)
    message = traceback.format_exception_only(type_, value)
    message = trace + "\n".join(message)

    return message