Skip to content

Commit 7d72810

Browse files
committed
Fix mypy type annotations for _to_thread_with_lock
Add TypeVar to preserve return types through the _to_thread_with_lock wrapper method. This fixes mypy errors about returning Any from functions with concrete return type declarations. - Import Callable and TypeVar from typing - Add generic TypeVar T - Annotate _to_thread_with_lock with proper generic types - Annotate wrapped() inner function return type
1 parent a4d77fe commit 7d72810

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/agents/memory/sqlite_session.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import sqlite3
66
import threading
77
from pathlib import Path
8+
from typing import Callable, TypeVar
89

910
from ..items import TResponseInputItem
1011
from .session import SessionABC
1112

13+
T = TypeVar("T")
14+
1215

1316
class SQLiteSession(SessionABC):
1417
"""SQLite-based implementation of session storage.
@@ -54,7 +57,7 @@ def _get_connection(self) -> sqlite3.Connection:
5457
"""Get a database connection."""
5558
return self._shared_connection
5659

57-
async def _to_thread_with_lock(self, func, *args, **kwargs):
60+
async def _to_thread_with_lock(self, func: Callable[..., T], *args, **kwargs) -> T:
5861
"""Execute a function in a thread pool with lock protection.
5962
6063
This ensures thread-safe access to the shared database connection
@@ -70,7 +73,7 @@ async def _to_thread_with_lock(self, func, *args, **kwargs):
7073
The result of the function execution
7174
"""
7275

73-
def wrapped():
76+
def wrapped() -> T:
7477
with self._lock:
7578
return func(*args, **kwargs)
7679

0 commit comments

Comments
 (0)