Skip to content

Commit 6f69adb

Browse files
AdamMaguedclaude
andcommitted
fix(context_meter): satisfy pyright narrowing in _tools_cache_key
pyright doesn't narrow across two separate t.get("parameters") calls, so it flagged .keys() as reachable when t.get("parameters") is None even though the isinstance(..., dict) guard makes that unreachable at runtime. Binds t.get("parameters") to a local once and isinstance-checks that — a real (if narrow) robustness improvement too, since it drops a redundant second dict lookup. No behavior change; confirmed via `pyright orchestrator/context_meter.py` -> 0 errors, and tests/test_context_meter.py + tests/test_compaction.py still green. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 7f37580 commit 6f69adb

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎orchestrator/context_meter.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,15 @@ def _tools_cache_key(tools: list[dict]) -> tuple:
274274
name) without paying for a full JSON serialization on every call.
275275
"""
276276
try:
277+
def _param_keys(tool: dict) -> tuple | None:
278+
params = tool.get("parameters")
279+
return tuple(sorted(params.keys())) if isinstance(params, dict) else None
280+
277281
return tuple(
278282
(
279283
t.get("name"),
280284
len(str(t.get("description") or "")),
281-
tuple(sorted(t.get("parameters").keys()))
282-
if isinstance(t.get("parameters"), dict) else None,
285+
_param_keys(t),
283286
)
284287
for t in tools
285288
)

0 commit comments

Comments
 (0)