def _try_cast(obj, cls):
    """Attempts to cast an object to a class, returning the resulting casted
    object or the original object if the cast raises a ValueError.
    """

    try:
        return cls(obj)
    except ValueError:
        return obj