Skip to content

Commit d8f0098

Browse files
committed
scripts(typing[mcp_swap]): narrow claude project node via isinstance
CI's ``uv run mypy .`` flagged ``Returning Any from function declared to return "dict[str, Any] | None"`` at the return of ``_claude_project_node``: ``projects.get(key)`` produces ``Any`` and the existing inner shape guard didn't propagate that narrowing to the return site. Replace the post-hoc check with an isinstance-narrowed assignment: ``raw_node`` stays ``Any`` from ``projects.get`` but the ``isinstance(raw_node, dict)`` branch narrows it onto a typed ``node: dict[str, t.Any] | None``. Same runtime behaviour (the non-None / non-dict path still raises ``RuntimeError``) without ``t.cast``. This supersedes a transient ``t.cast`` fix on this branch.
1 parent 0820805 commit d8f0098

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

scripts/mcp_swap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,15 @@ def _claude_project_node(
275275
projects = (
276276
config.setdefault("projects", {}) if create else config.get("projects", {})
277277
)
278-
node = projects.get(key)
279-
if node is not None and not isinstance(node, dict):
278+
raw_node = projects.get(key)
279+
node: dict[str, t.Any] | None = None
280+
if isinstance(raw_node, dict):
281+
node = raw_node
282+
elif raw_node is not None:
280283
msg = (
281284
"Claude config layout appears to have changed; expected "
282285
f"'projects[{key!r}]' to be a mapping but got "
283-
f"{type(node).__name__}"
286+
f"{type(raw_node).__name__}"
284287
)
285288
raise RuntimeError(msg)
286289
if node is None and create:

0 commit comments

Comments
 (0)