def format_message(fname, expected, actual, flag):
    """
    Convenience function that returns nicely formatted error/warning messages
    """

    def _format(types):
        return ', '.join([str(t).split("'")[1] for t in types])

    expected, actual = _format(expected), _format(actual)
    msg = "'{}' method ".format(fname) + ('accepts', 'returns')[flag] + ' ({}), but '.format(expected) + \
          ('was given', 'result is')[flag] + ' ({})'.format(actual)
    return msg