From 7a858470fe9fea909fce9472dbb361f7be4c2ca1 Mon Sep 17 00:00:00 2001 From: Twisha Bansal <58483338+twishabansal@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:51:13 +0530 Subject: [PATCH 1/4] fix: make tool annotations read-only --- packages/toolbox-core/src/toolbox_core/sync_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolbox-core/src/toolbox_core/sync_tool.py b/packages/toolbox-core/src/toolbox_core/sync_tool.py index ad24e8e3..ddeedaca 100644 --- a/packages/toolbox-core/src/toolbox_core/sync_tool.py +++ b/packages/toolbox-core/src/toolbox_core/sync_tool.py @@ -85,7 +85,7 @@ def __annotations__(self) -> dict[str, Any]: # type: ignore[override] # Standard Python object attributes like __doc__ are technically "writable". # But not defining a setter function makes this a read-only property. # Mypy flags this issue in the type checks. - return self.__async_tool.__annotations__ + return self.__async_tool.__annotations__.copy() def __call__(self, *args: Any, **kwargs: Any) -> str: """ From 104ea2b5798959be3f1795e56df8ec6d5fefa13a Mon Sep 17 00:00:00 2001 From: Twisha Bansal <58483338+twishabansal@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:59:14 +0530 Subject: [PATCH 2/4] Update sync_tool.py --- packages/toolbox-core/src/toolbox_core/sync_tool.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/toolbox-core/src/toolbox_core/sync_tool.py b/packages/toolbox-core/src/toolbox_core/sync_tool.py index ddeedaca..b4378338 100644 --- a/packages/toolbox-core/src/toolbox_core/sync_tool.py +++ b/packages/toolbox-core/src/toolbox_core/sync_tool.py @@ -13,6 +13,7 @@ # limitations under the License. import asyncio +import types from asyncio import AbstractEventLoop from inspect import Signature from threading import Thread @@ -85,7 +86,7 @@ def __annotations__(self) -> dict[str, Any]: # type: ignore[override] # Standard Python object attributes like __doc__ are technically "writable". # But not defining a setter function makes this a read-only property. # Mypy flags this issue in the type checks. - return self.__async_tool.__annotations__.copy() + return types.MappingProxyType(self.__async_tool.__annotations__) def __call__(self, *args: Any, **kwargs: Any) -> str: """ From 663d4a645ba8106981e3cf8971b8a6959d04cd78 Mon Sep 17 00:00:00 2001 From: Twisha Bansal <58483338+twishabansal@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:01:03 +0530 Subject: [PATCH 3/4] Update sync_tool.py --- packages/toolbox-core/src/toolbox_core/sync_tool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/toolbox-core/src/toolbox_core/sync_tool.py b/packages/toolbox-core/src/toolbox_core/sync_tool.py index b4378338..9be105aa 100644 --- a/packages/toolbox-core/src/toolbox_core/sync_tool.py +++ b/packages/toolbox-core/src/toolbox_core/sync_tool.py @@ -82,7 +82,7 @@ def __signature__(self) -> Signature: return self.__async_tool.__signature__ @property - def __annotations__(self) -> dict[str, Any]: # type: ignore[override] + def __annotations__(self) -> MappingProxyType[str, Any]: # type: ignore[override] # Standard Python object attributes like __doc__ are technically "writable". # But not defining a setter function makes this a read-only property. # Mypy flags this issue in the type checks. From aab5f136332e9fdb072a1e8d619c27f6eedb2988 Mon Sep 17 00:00:00 2001 From: Twisha Bansal <58483338+twishabansal@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:03:01 +0530 Subject: [PATCH 4/4] Update sync_tool.py --- packages/toolbox-core/src/toolbox_core/sync_tool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/toolbox-core/src/toolbox_core/sync_tool.py b/packages/toolbox-core/src/toolbox_core/sync_tool.py index 9be105aa..6e3179ed 100644 --- a/packages/toolbox-core/src/toolbox_core/sync_tool.py +++ b/packages/toolbox-core/src/toolbox_core/sync_tool.py @@ -13,10 +13,10 @@ # limitations under the License. import asyncio -import types from asyncio import AbstractEventLoop from inspect import Signature from threading import Thread +from types import MappingProxyType from typing import Any, Callable, Mapping, TypeVar, Union from .tool import ToolboxTool @@ -86,7 +86,7 @@ def __annotations__(self) -> MappingProxyType[str, Any]: # type: ignore[overrid # Standard Python object attributes like __doc__ are technically "writable". # But not defining a setter function makes this a read-only property. # Mypy flags this issue in the type checks. - return types.MappingProxyType(self.__async_tool.__annotations__) + return MappingProxyType(self.__async_tool.__annotations__) def __call__(self, *args: Any, **kwargs: Any) -> str: """