add env bool getting #6

Open
opened 2026-07-06 20:35:57 +02:00 by brian · 0 comments
Owner

_TRUTHY = frozenset({"1", "true", "yes", "on"})
_FALSY = frozenset({"0", "false", "no", "off"})

def _env_bool(name: str, default: bool) -> bool:
raw = os.getenv(name)
if raw is None:
return default
normalized = raw.strip().lower()
if normalized in _TRUTHY:
return True
if normalized in _FALSY:
return False
raise ValueError(f"Invalid boolean value for {name}: {raw!r}")

_TRUTHY = frozenset({"1", "true", "yes", "on"}) _FALSY = frozenset({"0", "false", "no", "off"}) def _env_bool(name: str, default: bool) -> bool: raw = os.getenv(name) if raw is None: return default normalized = raw.strip().lower() if normalized in _TRUTHY: return True if normalized in _FALSY: return False raise ValueError(f"Invalid boolean value for {name}: {raw!r}")
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: brian/python-utils#6