chore: remove deprecated deserialize tools inplace function (#9379)

* rm deserialize_tools_inplace + clean up

* release note
This commit is contained in:
Stefano Fiorucci 2025-05-13 09:27:36 +02:00 committed by GitHub
parent 9f2c0679d4
commit 1541d93670
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 34 deletions

View File

@ -6,7 +6,7 @@
# ruff: noqa: I001 (ignore import order as we need to import Tool before ComponentTool)
from .from_function import create_tool_from_function, tool
from .tool import Tool, _check_duplicate_tool_names, deserialize_tools_inplace
from .tool import Tool, _check_duplicate_tool_names
from .component_tool import ComponentTool
from .serde_utils import deserialize_tools_or_toolset_inplace, serialize_tools_or_toolset
from .toolset import Toolset
@ -15,7 +15,6 @@ __all__ = [
"_check_duplicate_tool_names",
"ComponentTool",
"create_tool_from_function",
"deserialize_tools_inplace",
"deserialize_tools_or_toolset_inplace",
"serialize_tools_or_toolset",
"Tool",

View File

@ -2,18 +2,16 @@
#
# SPDX-License-Identifier: Apache-2.0
from typing import TYPE_CHECKING, Any, Dict, List, Union
from typing import Any, Dict, List, Union
from haystack.core.errors import DeserializationError
from haystack.core.serialization import import_class_by_name
if TYPE_CHECKING:
from haystack.tools.tool import Tool
from haystack.tools.toolset import Toolset
from haystack.tools.tool import Tool
from haystack.tools.toolset import Toolset
def serialize_tools_or_toolset(
tools: Union["Toolset", List["Tool"], None],
tools: Union[Toolset, List[Tool], None],
) -> Union[Dict[str, Any], List[Dict[str, Any]], None]:
"""
Serialize a Toolset or a list of Tools to a dictionary or a list of tool dictionaries.
@ -21,8 +19,6 @@ def serialize_tools_or_toolset(
:param tools: A Toolset, a list of Tools, or None
:returns: A dictionary, a list of tool dictionaries, or None if tools is None
"""
from haystack.tools.toolset import Toolset
if tools is None:
return None
if isinstance(tools, Toolset):
@ -39,9 +35,6 @@ def deserialize_tools_or_toolset_inplace(data: Dict[str, Any], key: str = "tools
:param key:
The key in the dictionary where the list of Tools or Toolset is stored.
"""
from haystack.tools.tool import Tool
from haystack.tools.toolset import Toolset
if key in data:
serialized_tools = data[key]

View File

@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
import warnings
from dataclasses import asdict, dataclass
from typing import Any, Callable, Dict, List, Optional
@ -11,7 +10,6 @@ from jsonschema.exceptions import SchemaError
from haystack.core.serialization import generate_qualified_class_name
from haystack.tools.errors import ToolInvocationError
from haystack.tools.serde_utils import deserialize_tools_or_toolset_inplace
from haystack.utils import deserialize_callable, serialize_callable
@ -175,22 +173,3 @@ def _check_duplicate_tool_names(tools: Optional[List[Tool]]) -> None:
duplicate_tool_names = {name for name in tool_names if tool_names.count(name) > 1}
if duplicate_tool_names:
raise ValueError(f"Duplicate tool names found: {duplicate_tool_names}")
def deserialize_tools_inplace(data: Dict[str, Any], key: str = "tools"):
"""
Deserialize a list of Tools or a Toolset in a dictionary inplace.
Deprecated in favor of `deserialize_tools_or_toolset_inplace`. It will be removed in Haystack 2.14.0.
:param data:
The dictionary with the serialized data.
:param key:
The key in the dictionary where the list of Tools or Toolset is stored.
"""
warnings.warn(
"`deserialize_tools_inplace` is deprecated and will be removed in Haystack 2.14.0. "
"Use `deserialize_tools_or_toolset_inplace` instead.",
DeprecationWarning,
)
deserialize_tools_or_toolset_inplace(data, key)

View File

@ -0,0 +1,6 @@
---
upgrade:
- |
The deprecated `deserialize_tools_inplace` utility function has been removed.
Use `deserialize_tools_or_toolset_inplace` instead, importing it as follows:
`from haystack.tools import deserialize_tools_or_toolset_inplace`.