Ejemplo n.º 1
0
def soft_cast(value, cast_type):
    """
    cast a value to a given type, if the cast fails, cast to null

    Example:
        >>> cast(None, int)
        None
        >>> cast('', int)
        None
    """
    try:
        return cast(value, cast_type)
    except (TypeError, ValueError):
        pass
    return tab.cast_null(value)
Ejemplo n.º 2
0
 def soft_null_cast(value):
     try:
         tab.cast_null(value)
     except TypeError:
         return value