_pick.py 423 B

1234567891011121314151617
  1. from typing import Optional
  2. def pick_bool(*values: Optional[bool]) -> bool:
  3. """Pick the first non-none bool or return the last value.
  4. Args:
  5. *values (bool): Any number of boolean or None values.
  6. Returns:
  7. bool: First non-none boolean.
  8. """
  9. assert values, "1 or more values required"
  10. for value in values:
  11. if value is not None:
  12. return value
  13. return bool(value)