From c65dfd5d3785326dbb6fba7f16c34731048b76f6 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 1 Sep 2026 11:26:02 -0700 Subject: [PATCH] refactor(websearch): build the search tool lists as tuples The restored code seeded two mutable lists, which trips LIT002 now that the type-discipline budget has ratcheted past what they cost Build both in one shot as tuples and widen the parameter to Sequence so the single caller still type checks. No behavior change, both are only ever read --- litellm/integrations/websearch_interception/handler.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index 3694bf70b48..dc61ee38a8c 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -1633,16 +1633,18 @@ class WebSearchInterceptionLogger(CustomLogger): def _select_search_tool_from_router(self, llm_router: object) -> "_SearchToolConfig | None": if llm_router is None or not hasattr(llm_router, "search_tools"): return None - search_tools: Final = list(getattr(llm_router, "search_tools", None) or []) + search_tools: Final = tuple(getattr(llm_router, "search_tools", None) or ()) return self._select_search_tool_from_list(search_tools=search_tools, source="router") def _select_search_tool_from_list( self, - search_tools: list[_SearchToolConfig], + search_tools: Sequence[_SearchToolConfig], source: str, ) -> "_SearchToolConfig | None": if self.search_tool_name: - matching_tools = [tool for tool in search_tools if tool.get("search_tool_name") == self.search_tool_name] + matching_tools: Final = tuple( + tool for tool in search_tools if tool.get("search_tool_name") == self.search_tool_name + ) if matching_tools: search_provider = (matching_tools[0].get("litellm_params", {}) or {}).get("search_provider") verbose_logger.debug(