def METHOD_NAME(typ, value, name):
    if value is None:
        return None
    if isinstance(value, typ):
        return value
    try:
        return typ(value)
    except (TypeError, ValueError, ArithmeticError) as err:
        raise InvalidArgument(
            f"Cannot convert {name}={value!r} of type "
            f"{type(value).__name__} to type {typ.__name__}"
        ) from err