from typing import Any
from typing import Callable


def _cast(payload: Any, castFunc: Callable[[Any], Any], strict: bool = True) -> Any:
	"""Handy cast function. Raises a ValueError if fails when strict=True else...

	returns data unconverted.

	Args:
		payload (Any): data to convert
		castFunc (Callable[[Any], Any]): cast function eg int
		strict (bool, optional): throw error if true, otherwise return payload.
		Defaults to True.

	Raises:
		ValueError: if the cast fails and strict=True

	Returns:
		Any: casted payload
	"""
	try:
		payload = castFunc(payload)
	except ValueError as error:
		if strict:
			raise error
	return payload