def type_error(func_name, expect_tp, got_tp, arg_name=None, ret=False
    ) ->TypeError:
    """format type error message."""
    msg = func_name
    if ret:
        msg += f"'s return"
    elif arg_name:
        msg += f"'s parameter '{arg_name}'"
    msg += f' expect type {expect_tp}, got {got_tp}.'
    return TypeError(msg)
