def type_error(expected_type, x_type, x_name, extra_msg=None):
    """returns a commonly formatted type error which can then be raised by individual methods"""
    extra_msg = '' if extra_msg is None else '  ' + extra_msg
    return TypeError("Value for %s is of type %s.  Expected type %s.%s" % (x_name, x_type, expected_type, extra_msg))