Skip to content

Commit 0b8e45c

Browse files
Fix mypy package resolution for AgentKit tests
1 parent 0ec6519 commit 0b8e45c

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/agora_agent/core/pydantic_utilities.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,15 @@ class V2RootModel(UniversalBaseModel, pydantic.RootModel): # type: ignore[misc,
209209

210210

211211
def encode_by_type(o: Any) -> Any:
212-
encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(tuple)
212+
encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[type[Any], ...]] = {}
213213
for type_, encoder in encoders_by_type.items():
214-
encoders_by_class_tuples[encoder] += (type_,)
214+
typed_encoder = cast(Callable[[Any], Any], encoder)
215+
typed_type = cast(type[Any], type_)
216+
encoders_by_class_tuples[typed_encoder] = encoders_by_class_tuples.get(typed_encoder, ()) + (typed_type,)
215217

216218
if type(o) in encoders_by_type:
217-
return encoders_by_type[type(o)](o)
219+
encoder = cast(Callable[[Any], Any], encoders_by_type[type(o)])
220+
return encoder(o)
218221
for encoder, classes_tuple in encoders_by_class_tuples.items():
219222
if isinstance(o, classes_tuple):
220223
return encoder(o)

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file makes the test suite an explicit package for mypy module resolution.

tests/agentkit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file makes the AgentKit test suite an explicit package for mypy module resolution.

tests/agentkit/test_agentkit_parity.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Any, Dict, List, Tuple
12
from types import SimpleNamespace
23
import unittest
34

@@ -16,8 +17,8 @@
1617

1718
class DummyAgents:
1819
def __init__(self) -> None:
19-
self.start_calls = []
20-
self.turn_calls = []
20+
self.start_calls: List[Tuple[Any, Dict[str, Any]]] = []
21+
self.turn_calls: List[Tuple[Any, Any, Any]] = []
2122

2223
def start(self, app_id, **kwargs):
2324
self.start_calls.append((app_id, kwargs))

0 commit comments

Comments
 (0)