Skip to content

Commit

Permalink
Added to_boolean to misc_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Nov 20, 2023
1 parent 4d40798 commit 471f05b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions dcicutils/misc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,15 @@ def to_float(value: str, fallback: Optional[Any] = None) -> Optional[Any]:
return fallback


def to_boolean(value: str, fallback: Optional[Any]) -> Optional[Any]:
if isinstance(value, str) and (value := value.strip().lower()):
if (lower_value := value.lower()) in ["true", "t"]:
return True
elif lower_value in ["false", "f"]:
return False
return fallback


@contextlib.contextmanager
def override_environ(**overrides):
"""
Expand Down

0 comments on commit 471f05b

Please sign in to comment.