INNER CODE UNIT · Python
to_int
OpenChemistry/avogadrolibs · scripts/coverage_summary.py:95
def to_int(value: str | None) -> int | None:
try:
return int(value) # type: ignore[arg-type]
except (TypeError, ValueError):
return None
def previous_pct(row: dict[str, str] | None, covered: str, total: str):
if row is None:
return None
c, t = to_int(row.get(covered)), to_int(row.get(total))
if c is None or t is None:
return None
return pct(c, t)
def fmt_pct(value: float | None) -> str:
return "n/a" if value is None else f"{value:.1f}"