From 87f8c0575d08c2b8f6d5ff6dafec62045d34b445 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sat, 20 Jun 2026 10:38:18 -0400 Subject: [PATCH] refactor(mcp_client): migrate L171 _is_allowed to Path.is_relative_to (Phase 8 site 1) The legacy code used 'try: rp.relative_to(cwd); return True; except ValueError: pass' to check path containment. Python 3.9+ has Path.is_relative_to() which returns bool directly, eliminating the silent-swallow try/except entirely. This is a NON-SLIMING migration: the function's behavior is unchanged (still returns True/False), the test of path containment is the same, but the implementation no longer relies on bare except+pass. No logging added, no silenced error, just a cleaner API. Audit: mcp_client INTERNAL_SILENT_SWALLOW 3 -> 2. --- src/mcp_client.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/mcp_client.py b/src/mcp_client.py index c7c70a18..dd531059 100644 --- a/src/mcp_client.py +++ b/src/mcp_client.py @@ -165,17 +165,11 @@ def _is_allowed(path: Path) -> bool: # Allow current working directory and subpaths by default if no base_dirs cwd = Path.cwd().resolve() if not _base_dirs: - try: - rp.relative_to(cwd) + if rp.is_relative_to(cwd): return True - except ValueError: - pass for bd in _base_dirs: - try: - rp.relative_to(bd) + if rp.is_relative_to(bd): return True - except ValueError: - continue return False def _resolve_and_check(raw_path: str) -> tuple[Path | None, str]: