mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-27 06:13:07 +00:00
refactor(typing): widen delete_nested_value to Mapping and drop two unused Span aliases (#48001)
* refactor(typing): replace pass-through Any with object in 13 annotations * docs(client): say dict[str, object] in the models get docstring * refactor(typing): drop the unused Span aliases in base_cache and levo * refactor(typing): take a Mapping in delete_nested_value and cover the fresh copy * fix(typing): deep-copy a read-only Mapping in delete_nested_value through a dict
This commit is contained in:
parent
e6a32bbeeb
commit
d0671f75a4
5 changed files with 18 additions and 15 deletions
|
|
@ -9,14 +9,7 @@ Has 4 methods:
|
|||
"""
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from opentelemetry.trace import Span as _Span
|
||||
|
||||
Span = _Span
|
||||
else:
|
||||
Span = Any
|
||||
from typing import Final
|
||||
|
||||
|
||||
class BaseCache(ABC):
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ from typing import TYPE_CHECKING, Any, Final
|
|||
from litellm.integrations.opentelemetry import OpenTelemetry
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from opentelemetry.trace import Span as _Span
|
||||
|
||||
from litellm.integrations.opentelemetry import (
|
||||
OpenTelemetryConfig as _OpenTelemetryConfig,
|
||||
)
|
||||
|
|
@ -13,11 +11,9 @@ if TYPE_CHECKING:
|
|||
|
||||
Protocol = _Protocol
|
||||
OpenTelemetryConfig = _OpenTelemetryConfig
|
||||
Span = _Span
|
||||
else:
|
||||
Protocol = Any
|
||||
OpenTelemetryConfig = Any
|
||||
Span = Any
|
||||
|
||||
|
||||
class LevoConfig:
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ def _delete_nested_value_custom(
|
|||
|
||||
|
||||
def delete_nested_value(
|
||||
data: dict[str, object],
|
||||
data: Mapping[str, object],
|
||||
path: str,
|
||||
depth: int = 0,
|
||||
max_depth: int = 20,
|
||||
|
|
@ -214,7 +214,7 @@ def delete_nested_value(
|
|||
"""
|
||||
import copy
|
||||
|
||||
result: Final = copy.deepcopy(data)
|
||||
result: Final = copy.deepcopy(data if isinstance(data, dict) else dict(data))
|
||||
|
||||
try:
|
||||
# Parse path into segments
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ class ModelsManagementClient:
|
|||
return_request (bool): If True, returns the prepared request object instead of executing it
|
||||
|
||||
Returns:
|
||||
Union[Dict[str, Any], requests.Request]: Either the model information from the server or
|
||||
dict[str, object] | requests.Request: Either the model information from the server or
|
||||
a prepared request object if return_request is True
|
||||
|
||||
Raises:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
Tests for litellm.litellm_core_utils.dot_notation_indexing module.
|
||||
"""
|
||||
|
||||
from types import MappingProxyType
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
|
||||
from litellm.litellm_core_utils.dot_notation_indexing import (
|
||||
|
|
@ -125,3 +128,14 @@ class TestDeleteNestedValue:
|
|||
data = {"items": [{"a": 1, "b": 2}, {"a": 3, "b": 4}]}
|
||||
result = delete_nested_value(data, "items[0].b")
|
||||
assert result == {"items": [{"a": 1}, {"a": 3, "b": 4}]}
|
||||
|
||||
def test_delete_returns_a_fresh_dict_and_leaves_a_narrowly_typed_input_untouched(self):
|
||||
payload: Final[dict[str, list[str]]] = {"tags": ["a", "b"], "secret": ["s"]}
|
||||
result = delete_nested_value(payload, "secret")
|
||||
assert result == {"tags": ["a", "b"]}
|
||||
assert payload == {"tags": ["a", "b"], "secret": ["s"]}
|
||||
assert result["tags"] is not payload["tags"]
|
||||
|
||||
def test_delete_accepts_a_read_only_mapping(self):
|
||||
payload: Final = MappingProxyType({"tags": ["a"], "secret": ["s"]})
|
||||
assert delete_nested_value(payload, "secret") == {"tags": ["a"]}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue