From 59ea2a579247f60f3bcce17d416852c608d4d866 Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 18:03:38 +0800 Subject: [PATCH 1/4] Fix mutable default argument in InfinityError.__init__ Use None as default and initialize empty dict inside the function to prevent mutable default argument anti-pattern. --- litellm/llms/infinity/common_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/llms/infinity/common_utils.py b/litellm/llms/infinity/common_utils.py index e23fe4a0d37..c3503c1f6c0 100644 --- a/litellm/llms/infinity/common_utils.py +++ b/litellm/llms/infinity/common_utils.py @@ -4,7 +4,9 @@ from litellm.llms.base_llm.chat.transformation import BaseLLMException class InfinityError(BaseLLMException): - def __init__(self, status_code: int, message: str, headers: dict | httpx.Headers = {}): + def __init__(self, status_code: int, message: str, headers: dict | httpx.Headers | None = None): + if headers is None: + headers = {} self.status_code = status_code self.message = message self.request = httpx.Request(method="POST", url="https://github.com/michaelfeil/infinity") From 490390a0578399097f310a820225d93822c5db6d Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 18:04:17 +0800 Subject: [PATCH 2/4] Fix mutable default argument in check_if_part_exists_in_parts Use None as default and initialize empty list inside the function to prevent mutable default argument anti-pattern. --- litellm/llms/vertex_ai/gemini/transformation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index e2d62be6a69..84a70ee3bae 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -613,11 +613,13 @@ def _get_equivalent_key(key: str, available_keys: set) -> str | None: return None -def check_if_part_exists_in_parts(parts: list[PartType], part: PartType, excluded_keys: list[str] = []) -> bool: +def check_if_part_exists_in_parts(parts: list[PartType], part: PartType, excluded_keys: list[str] | None = None) -> bool: """ Check if a part exists in a list of parts Handles both camelCase and snake_case key variations (e.g., function_call vs functionCall) """ + if excluded_keys is None: + excluded_keys = [] keys_to_compare: Final = set(part.keys()) - set(excluded_keys) for p in parts: p_keys = set(p.keys()) From 09bf95d20116fe095334c87a2d93cc9d19a5ac4a Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 4 Sep 2026 14:17:36 +0800 Subject: [PATCH 3/4] fix: avoid rebinding optional mutable inputs --- litellm/llms/infinity/common_utils.py | 5 ++--- litellm/llms/vertex_ai/gemini/transformation.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/litellm/llms/infinity/common_utils.py b/litellm/llms/infinity/common_utils.py index c3503c1f6c0..30a5f1006f7 100644 --- a/litellm/llms/infinity/common_utils.py +++ b/litellm/llms/infinity/common_utils.py @@ -5,8 +5,7 @@ from litellm.llms.base_llm.chat.transformation import BaseLLMException class InfinityError(BaseLLMException): def __init__(self, status_code: int, message: str, headers: dict | httpx.Headers | None = None): - if headers is None: - headers = {} + resolved_headers = {} if headers is None else headers self.status_code = status_code self.message = message self.request = httpx.Request(method="POST", url="https://github.com/michaelfeil/infinity") @@ -16,5 +15,5 @@ class InfinityError(BaseLLMException): message=message, request=self.request, response=self.response, - headers=headers, + headers=resolved_headers, ) # Call the base class constructor with the parameters it needs diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index 84a70ee3bae..170267b90d9 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -618,9 +618,8 @@ def check_if_part_exists_in_parts(parts: list[PartType], part: PartType, exclude Check if a part exists in a list of parts Handles both camelCase and snake_case key variations (e.g., function_call vs functionCall) """ - if excluded_keys is None: - excluded_keys = [] - keys_to_compare: Final = set(part.keys()) - set(excluded_keys) + resolved_excluded_keys = [] if excluded_keys is None else excluded_keys + keys_to_compare: Final = set(part.keys()) - set(resolved_excluded_keys) for p in parts: p_keys = set(p.keys()) # Check if all keys in part have equivalent values in p From 223e49e9ae157ac66223fef24e3962190263c957 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 4 Sep 2026 14:36:08 +0800 Subject: [PATCH 4/4] style: format Gemini transformation --- litellm/llms/vertex_ai/gemini/transformation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index 170267b90d9..93ae9058ed3 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -613,7 +613,9 @@ def _get_equivalent_key(key: str, available_keys: set) -> str | None: return None -def check_if_part_exists_in_parts(parts: list[PartType], part: PartType, excluded_keys: list[str] | None = None) -> bool: +def check_if_part_exists_in_parts( + parts: list[PartType], part: PartType, excluded_keys: list[str] | None = None +) -> bool: """ Check if a part exists in a list of parts Handles both camelCase and snake_case key variations (e.g., function_call vs functionCall)