def cast_bool(value):
    """Cast a value to a bool. Will properly detect strings such as "True", "T", "1".
    """
    if isinstance(value, str):
        return value.strip().lower() in ["t", "true", "1"]
    return bool(value)