Coverage for src/lilbee/core/config/parsing.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-09-17 10:02 +0000

1"""Boolean parsing helpers used by :mod:`lilbee.config` validators.""" 

2 

3# Matches what pydantic itself accepts for a bool field. Every other bool on 

4# Config is coerced by pydantic, so a narrower vocabulary here would make the 

5# same env spelling mean different things on different fields of one object. 

6_BOOL_TRUE = frozenset({"true", "t", "yes", "y", "on", "1"}) 

7_BOOL_FALSE = frozenset({"false", "f", "no", "n", "off", "0"}) 

8 

9 

10def parse_bool(raw: str) -> bool: 

11 """Parse a boolean env string; raises ValueError on anything else.""" 

12 normalized = raw.strip().lower() 

13 if normalized in _BOOL_TRUE: 

14 return True 

15 if normalized in _BOOL_FALSE: 

16 return False 

17 raise ValueError(f"Invalid boolean: {raw!r}")