From ae337448936c65e737e1bf845acd8da71d0e1fa0 Mon Sep 17 00:00:00 2001 From: jesset Date: Sun, 3 May 2026 17:29:37 +0800 Subject: [PATCH] fix: resolve MyPy type errors in conditional dict unpacking Replace `**({...} if cond else {})` pattern with direct dict mutation to avoid MyPy's inability to infer the correct type from conditional expressions in **kwargs unpacking. Co-Authored-By: Claude Opus 4.7 --- litellm/integrations/websearch_interception/handler.py | 4 ++-- litellm/llms/custom_httpx/llm_http_handler.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/litellm/integrations/websearch_interception/handler.py b/litellm/integrations/websearch_interception/handler.py index f00dda2d516..4a8c96630dd 100644 --- a/litellm/integrations/websearch_interception/handler.py +++ b/litellm/integrations/websearch_interception/handler.py @@ -771,15 +771,15 @@ class WebSearchInterceptionLogger(CustomLogger): followup_kwargs = dict(request_patch.kwargs) if _followup_api_key is not None: followup_kwargs.pop("api_key", None) + followup_kwargs["api_key"] = _followup_api_key if _followup_api_base is not None: followup_kwargs.pop("api_base", None) + followup_kwargs["api_base"] = _followup_api_base return await anthropic_messages.acreate( max_tokens=max_tokens, messages=request_patch.messages, model=request_patch.model or model, - **({"api_key": _followup_api_key} if _followup_api_key else {}), - **({"api_base": _followup_api_base} if _followup_api_base else {}), **optional_params, **followup_kwargs, ) diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.py index f3919573d41..57c6cd52df1 100644 --- a/litellm/llms/custom_httpx/llm_http_handler.py +++ b/litellm/llms/custom_httpx/llm_http_handler.py @@ -4683,8 +4683,10 @@ class BaseLLMHTTPHandler: # api_key or api_base, so agentic credentials take precedence. if agentic_api_key is not None: kwargs_for_followup.pop("api_key", None) + kwargs_for_followup["api_key"] = agentic_api_key if agentic_api_base is not None: kwargs_for_followup.pop("api_base", None) + kwargs_for_followup["api_base"] = agentic_api_base return await anthropic_messages.acreate( **{ @@ -4692,8 +4694,6 @@ class BaseLLMHTTPHandler: "messages": patch.messages, "model": patch.model or full_model_name, "stream": stream, - **({"api_key": agentic_api_key} if agentic_api_key else {}), - **({"api_base": agentic_api_base} if agentic_api_base else {}), **optional_params, **kwargs_for_followup, }