mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-19 09:53:33 +00:00
refactor(typing): take a Mapping in delete_nested_value and cover the fresh copy
This commit is contained in:
parent
0e77a203e8
commit
9432192d68
2 changed files with 12 additions and 2 deletions
|
|
@ -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,8 @@ def delete_nested_value(
|
|||
"""
|
||||
import copy
|
||||
|
||||
result: Final = copy.deepcopy(data)
|
||||
copied: Final = copy.deepcopy(data)
|
||||
result: Final = copied if isinstance(copied, dict) else dict(copied)
|
||||
|
||||
try:
|
||||
# Parse path into segments
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
Tests for litellm.litellm_core_utils.dot_notation_indexing module.
|
||||
"""
|
||||
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
|
||||
from litellm.litellm_core_utils.dot_notation_indexing import (
|
||||
|
|
@ -125,3 +127,10 @@ 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"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue