Skip to content

Commit cfc9a09

Browse files
committed
fix(memory): move Sequence to TYPE_CHECKING block, use hasattr for backend detection
- Import Sequence under TYPE_CHECKING to satisfy ruff UP035/TC003 - Use hasattr instead of isinstance(Protocol) for backend detection since runtime_checkable checks class attrs, not instance attrs, breaking MagicMock-based tests on Python 3.12+
1 parent 03bada8 commit cfc9a09

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/hawk/memory_tools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
from __future__ import annotations
1515

16-
from typing import Any, Protocol, Sequence, runtime_checkable
16+
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
17+
18+
if TYPE_CHECKING:
19+
from collections.abc import Sequence
1720

1821
from .tools import Tool
1922

@@ -46,7 +49,9 @@ def __init__(self, client: Any, *, session_id: str | None = None) -> None:
4649
self._session_id = session_id
4750
self._local_memories: list[dict[str, str]] = []
4851
self._backend: MemoryBackend | None = (
49-
client if isinstance(client, MemoryBackend) else None
52+
client
53+
if hasattr(client, "remember") and hasattr(client, "recall")
54+
else None
5055
)
5156

5257
def record_memory(

0 commit comments

Comments
 (0)