Typing, minor

This commit is contained in:
Michael Panchenko authored and Michael Panchenko committed 2025-07-08 13:59:42 +02:00
1 parent 06c3ed4459
commit 09b627fd16
2 files changed
+10 -4

No files matched your search

+1 -1
View File
@@ -435,7 +435,7 @@ class Symbol(ToStringMixin):
depth: int = 0,
include_body: bool = False,
include_children_body: bool = False,
include_relative_path=True,
include_relative_path: bool = True,
) -> dict[str, Any]:
"""
Converts the symbol to a dictionary.
+9 -3
View File
@@ -2,10 +2,10 @@ import inspect
import os
import traceback
from abc import ABC, abstractmethod
from collections.abc import Callable, Generator, Iterable
from collections.abc import Generator, Iterable
from copy import copy
from types import TracebackType
from typing import TYPE_CHECKING, Any, Self, TypeVar
from typing import TYPE_CHECKING, Any, Protocol, Self, TypeVar
from mcp.server.fastmcp.utilities.func_metadata import FuncMetadata, func_metadata
from sensai.util import logging
@@ -96,6 +96,12 @@ class ToolInterface(ABC):
...
class ApplyMethodProtocol(Protocol):
"""Callable protocol for the apply method of a tool."""
def __call__(self, *args: Any, **kwargs: Any) -> str: pass
class Tool(Component, ToolInterface):
# NOTE: each tool should implement the apply method, which is then used in
# the central method of the Tool class `apply_ex`.
@@ -119,7 +125,7 @@ class Tool(Component, ToolInterface):
def get_name(self) -> str:
return self.get_name_from_cls()
def get_apply_fn(self) -> Callable:
def get_apply_fn(self) -> ApplyMethodProtocol:
apply_fn = getattr(self, "apply")
if apply_fn is None:
raise RuntimeError(f"apply not defined in {self}. Did you forget to implement it?")