no-failure-conflated-with-absence
Distinguish a caught failure from a missing result.
Why
Callers cannot distinguish an operation that failed from a successful lookup with no result when both paths return None.
Fix
Let the failure propagate, or return a typed outcome with separate variants for a missing result and a failed operation.
Examples
from pathlib import Path
def read_score(path: Path, enabled: bool) -> int | None: if not enabled: return None try: return int(path.read_text()) except (OSError, ValueError): return Nonefrom pathlib import Path
from app.outcomes import MissingScore, ReadFailure, Score
def read_score(path: Path, enabled: bool) -> Score | MissingScore | ReadFailure: if not enabled: return MissingScore() try: return Score(int(path.read_text())) except (OSError, ValueError) as error: return ReadFailure(error)