sqlmesh.utils.conversions API documentation

Edit on GitHub

# sqlmesh.utils.conversions

View Source

     1from __future__ import annotations
     2
     3import typing as t
     4
     5
     6def ensure_bool(val: t.Any) -> bool:
     7    if isinstance(val, bool):
     8        return val
     9
    10    if val.isinstance(val, str):
    11        val = try_str_to_bool(val)
    12
    13    return bool(val)
    14
    15
    16def try_str_to_bool(val: str) -> t.Union[str, bool]:
    17    maybe_bool = val.lower()
    18    if maybe_bool in ["true", "false"]:
    19        return maybe_bool == "true"
    20
    21    return val

def ensure_bool(val: Any) -> bool: View Source

     7def ensure_bool(val: t.Any) -> bool:
     8    if isinstance(val, bool):
     9        return val
    10
    11    if val.isinstance(val, str):
    12        val = try_str_to_bool(val)
    13
    14    return bool(val)

def try_str_to_bool(val: str) -> Union[str, bool]: View Source

    17def try_str_to_bool(val: str) -> t.Union[str, bool]:
    18    maybe_bool = val.lower()
    19    if maybe_bool in ["true", "false"]:
    20        return maybe_bool == "true"
    21
    22    return val