safe_cast()
Safely cast a value to a target type.
Usage
safe_cast(
value,
target_type,
)May raise TypeError or ValueError.
Parameters
value: object-
The value to cast.
target_type: type-
The type to cast to.
Returns
object-
The cast value.
Raises
TypeError-
If the value cannot be cast to the target type.
ValueError-
If the value is invalid for the target type.