From 9ca3e41121741c23e451045e26a6c8a09af0ae2c Mon Sep 17 00:00:00 2001 From: "7. Sun" Date: Mon, 23 Mar 2026 13:40:48 +0000 Subject: [PATCH] fix: replace mutable default arguments with None in function signatures --- litellm/litellm_core_utils/litellm_logging.py | 6 ++++-- litellm/proxy/proxy_server.py | 3 ++- litellm/router_strategy/lowest_latency.py | 4 ++-- litellm/router_strategy/lowest_tpm_rpm.py | 4 ++-- litellm/types/utils.py | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index c127b3873a7..b41bbb7140b 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -950,7 +950,8 @@ class Logging(LiteLLMLoggingBaseClass): masked_api_base = api_base return str(masked_api_base) - def _pre_call(self, input, api_key, model=None, additional_args={}): + def _pre_call(self, input, api_key, model=None, additional_args=None): + additional_args = additional_args or {} """ Common helper function across the sync + async pre-call function """ @@ -967,7 +968,8 @@ class Logging(LiteLLMLoggingBaseClass): self._get_masked_api_base(additional_args.get("api_base", "")) ) - def pre_call(self, input, api_key, model=None, additional_args={}): # noqa: PLR0915 + def pre_call(self, input, api_key, model=None, additional_args=None): + additional_args = additional_args or {} # noqa: PLR0915 # Log the exact input to the LLM API litellm.error_logs["PRE_CALL"] = locals() try: diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index b296792cd09..60dbb6c1ebf 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7136,7 +7136,8 @@ def select_data_generator( ) -def get_litellm_model_info(model: dict = {}): +def get_litellm_model_info(model: dict = None): + model = model or {} model_info = model.get("model_info", {}) model_to_lookup = model.get("litellm_params", {}).get("model", None) try: diff --git a/litellm/router_strategy/lowest_latency.py b/litellm/router_strategy/lowest_latency.py index 870b3f29d48..89b17e5169c 100644 --- a/litellm/router_strategy/lowest_latency.py +++ b/litellm/router_strategy/lowest_latency.py @@ -31,9 +31,9 @@ class LowestLatencyLoggingHandler(CustomLogger): logged_success: int = 0 logged_failure: int = 0 - def __init__(self, router_cache: DualCache, routing_args: dict = {}): + def __init__(self, router_cache: DualCache, routing_args: dict = None): self.router_cache = router_cache - self.routing_args = RoutingArgs(**routing_args) + self.routing_args = RoutingArgs(**(routing_args or {})) def log_success_event( # noqa: PLR0915 self, kwargs, response_obj, start_time, end_time diff --git a/litellm/router_strategy/lowest_tpm_rpm.py b/litellm/router_strategy/lowest_tpm_rpm.py index 488f8450941..cd74e058c3c 100644 --- a/litellm/router_strategy/lowest_tpm_rpm.py +++ b/litellm/router_strategy/lowest_tpm_rpm.py @@ -22,9 +22,9 @@ class LowestTPMLoggingHandler(CustomLogger): logged_failure: int = 0 default_cache_time_seconds: int = 1 * 60 * 60 # 1 hour - def __init__(self, router_cache: DualCache, routing_args: dict = {}): + def __init__(self, router_cache: DualCache, routing_args: dict = None): self.router_cache = router_cache - self.routing_args = RoutingArgs(**routing_args) + self.routing_args = RoutingArgs(**(routing_args or {})) def log_success_event(self, kwargs, response_obj, start_time, end_time): try: diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 5574d616fac..63688fac768 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -3417,11 +3417,11 @@ class LiteLLMLoggingBaseClass: Meant to simplify type checking for logging obj. """ - def pre_call(self, input, api_key, model=None, additional_args={}): + def pre_call(self, input, api_key, model=None, additional_args=None): pass def post_call( - self, original_response, input=None, api_key=None, additional_args={} + self, original_response, input=None, api_key=None, additional_args=None ): pass