Skip to content

[Code Quality] Add _sanitize_fn to cache.__all__ to match api_client.py injection pattern #564

@github-actions

Description

@github-actions

Description

PR #538 (merged 2026-03-04) aligned cache.py's sanitization with api_client.py's _sanitize_fn injection pattern — both modules now expose a _sanitize_fn: Callable[[Any], str] injection point that main.py populates at startup to enable token-redacted logging.

However, cache.__all__ was not updated to export _sanitize_fn, creating an inconsistency with api_client.__all__ which explicitly exports it with the comment # injection point for token-aware sanitizer:

# api_client.py __all__ (line 46) — exports the injection point ✅
"_sanitize_fn",       # injection point for token-aware sanitizer

# cache.py __all__ (lines 38–45) — missing the injection point ❌
__all__ = [
    "CACHE_TTL_SECONDS",
    "_disk_cache",
    "_cache_stats",
    "get_cache_dir",
    "load_disk_cache",
    "save_disk_cache",
]

main.py injects the sanitizer via direct attribute access (cache._sanitize_fn = sanitize_for_log) rather than import, so this doesn't cause a runtime error — but it makes the module's intentional API less discoverable, and breaks the symmetry that PR #538 established.

Suggested Changes

In cache.py, add _sanitize_fn to __all__ with a matching comment:

__all__ = [
    "CACHE_TTL_SECONDS",
    "_disk_cache",       # live reference kept by main.py
    "_cache_stats",      # accessed by main.py for reporting
    "_sanitize_fn",      # injection point for token-aware sanitizer (see api_client.py)
    "get_cache_dir",
    "load_disk_cache",
    "save_disk_cache",
]

Files Affected

  • cache.py — add _sanitize_fn entry to __all__ (1-line change)

Success Criteria

  • cache.__all__ includes "_sanitize_fn" with explanatory comment
  • ✅ Entry mirrors the corresponding entry in api_client.__all__
  • ✅ All existing tests pass: uv run pytest tests/ -v
  • python -m py_compile cache.py succeeds

Source

Observed while reviewing the merged PRs listed in Daily QAReport – March 5, 2026 (#562): PR #538 aligned the _sanitize_fn injection pattern across cache.py and api_client.py, but cache.__all__ was not updated to match.

Priority

Low — 1-line fix. Improves API discoverability and keeps the two module contracts symmetric.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/discussion-task-miner.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
  • expires on Mar 6, 2026, 9:14 AM UTC

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions