Report incomplete filesystem traversal without revealing private paths
Also published in our Blogger archive.
Direct answer
A scanner should distinguish “no finding” from “could not inspect everything.” The small ScanResult model exposes a file count, an error count, and a derived completeness flag. The synthetic None represents an unreadable entry, and the assertion proves that two visible files do not make the run complete.
Counting failures rather than printing raw paths can preserve a useful operational signal without putting private directory names into a report. The edge case is a partial walk that otherwise looks normal: a filename-only score based on those two files must carry complete=no so a reviewer can judge its confidence.
This code does not catch actual OSError from Path.iterdir, classify permission errors, or retain per-directory diagnostics for an administrator. Those choices depend on the environment. It demonstrates the reporting contract: failure changes completeness, and completeness is not silently inferred from a nonempty result list.
Complete example
from dataclasses import dataclass
@dataclass(frozen=True)
class ScanResult:
files: int
errors: int
@property
def complete(self) -> bool:
return self.errors == 0
results = ["README.md", None, "src/main.py"]
summary = ScanResult(files=sum(item is not None for item in results), errors=results.count(None))
assert (summary.files, summary.errors, summary.complete) == (2, 1, False)
print("files=2 errors=1 complete=no")
Expected stdout:
files=2 errors=1 complete=no
Sources
Prepared with AI assistance. The example uses synthetic data; its stated limits apply.