mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
refactor(types): replace Any with proven types in 5 files (#42722)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
bc3b5b1d5b
commit
860bc7811d
5 changed files with 11 additions and 11 deletions
|
|
@ -9,7 +9,7 @@ import sys
|
|||
from collections.abc import Iterator
|
||||
from datetime import datetime
|
||||
from logging import Formatter
|
||||
from typing import Any, Final, TextIO
|
||||
from typing import Final, TextIO
|
||||
from urllib.parse import unquote
|
||||
|
||||
import litellm
|
||||
|
|
@ -672,13 +672,13 @@ def _try_parse_json_message(message: str) -> dict[str, object] | None:
|
|||
msg_stripped: Final = message.strip()
|
||||
if not (msg_stripped.startswith("{") or msg_stripped.startswith("[")):
|
||||
return None
|
||||
parsed: Final = safe_json_loads(message, default=None)
|
||||
parsed: Final[object] = safe_json_loads(message, default=None)
|
||||
if parsed is None or not isinstance(parsed, dict):
|
||||
return None
|
||||
return parsed
|
||||
|
||||
|
||||
def _try_parse_embedded_python_dict(message: str) -> dict[str, Any] | None:
|
||||
def _try_parse_embedded_python_dict(message: str) -> dict[str, object] | None:
|
||||
"""
|
||||
Try to find and parse a Python dict repr (e.g. str(d) or repr(d)) embedded in
|
||||
the message. Handles patterns like:
|
||||
|
|
@ -702,7 +702,7 @@ def _try_parse_embedded_python_dict(message: str) -> dict[str, Any] | None:
|
|||
if depth == 0:
|
||||
substr = message[start : j + 1]
|
||||
try:
|
||||
result = ast.literal_eval(substr)
|
||||
result: object = ast.literal_eval(substr)
|
||||
if isinstance(result, dict) and len(result) > 0:
|
||||
return result
|
||||
except (ValueError, SyntaxError, TypeError):
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class AmazonTwelveLabsPegasusConfig(AmazonInvokeConfig, BaseConfig):
|
|||
optional_params["responseFormat"] = self._normalize_response_format(value)
|
||||
return optional_params
|
||||
|
||||
def _normalize_response_format(self, value: Any) -> Any:
|
||||
def _normalize_response_format(self, value: Any) -> object:
|
||||
"""Normalize response_format to TwelveLabs format.
|
||||
|
||||
TwelveLabs expects:
|
||||
|
|
|
|||
|
|
@ -358,13 +358,13 @@ class GenAIHubOrchestrationConfig(OpenAIGPTConfig):
|
|||
)
|
||||
)
|
||||
|
||||
config_payload: Final[dict[str, Any]] = {
|
||||
config_payload: Final[dict[str, object]] = {
|
||||
"modules": modules if len(modules) > 1 else modules[0],
|
||||
}
|
||||
if stream_config:
|
||||
config_payload["stream"] = stream_config
|
||||
|
||||
request_body: Final[dict[str, Any]] = {"config": config_payload}
|
||||
request_body: Final[dict[str, object]] = {"config": config_payload}
|
||||
if placeholder_values is not None:
|
||||
request_body["placeholder_values"] = placeholder_values
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# litellm/proxy/guardrails/guardrail_hooks/pangea.py
|
||||
import os
|
||||
from typing import TYPE_CHECKING, Any, Final, cast
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ class PangeaHandler(CustomGuardrail):
|
|||
messages: Final = data.get("messages")
|
||||
if messages is None:
|
||||
return # No messages to check
|
||||
input_messages = cast(list[dict[Any, Any]], messages)
|
||||
input_messages = messages
|
||||
else:
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def get_instance_fn(value: str, config_file_path: str | None = None) -> Any:
|
|||
module = importlib.import_module(module_name)
|
||||
|
||||
# Get the instance from the module
|
||||
instance: Final = getattr(module, instance_name)
|
||||
instance: Final[object] = getattr(module, instance_name)
|
||||
|
||||
return instance
|
||||
except ImportError as e:
|
||||
|
|
@ -167,7 +167,7 @@ def _load_instance_from_remote_storage(remote_url: str, config_file_path: str |
|
|||
spec.loader.exec_module(module)
|
||||
|
||||
# Get the instance
|
||||
instance: Final = getattr(module, instance_name)
|
||||
instance: Final[object] = getattr(module, instance_name)
|
||||
|
||||
# Clean up the temporary file
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue