Skip to content

Commit 59f414c

Browse files
authored
Merge pull request #130 from ai-agent-assembly/v0.0.1/AAASM-3017/lint/clear_mypy
[AAASM-3017] 🚨 (python-sdk): Clear pre-existing mypy errors
2 parents 3bbda20 + e3bb734 commit 59f414c

36 files changed

Lines changed: 311 additions & 269 deletions

.pre-commit-config.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,25 @@ repos:
4545
build|
4646
dist"""
4747

48-
- repo: https://github.com/pre-commit/mirrors-mypy
49-
rev: v1.16.0
48+
- repo: local
5049
hooks:
5150
- id: mypy
52-
package: agent_assembly,test
53-
# exclude: ^test/unit_test.{1,64}.py
51+
name: mypy
52+
# Run mypy inside the uv-managed project env so it resolves the SDK's
53+
# runtime + optional framework deps (pydantic, httpx, pydantic-ai, …).
54+
# The upstream mirrors-mypy hook installs into an isolated venv that lacks
55+
# these, which made every BaseModel/framework subclass resolve to `Any`.
56+
# Type-check the whole project via mypy.ini's `packages =` discovery (no
57+
# file paths) so the generated proto .py/.pyi pairs don't trip a
58+
# "Duplicate module" error and the hook stays identical to the configured
59+
# `mypy` invocation.
60+
entry: uv run mypy
61+
language: system
62+
types: [python]
63+
pass_filenames: false
5464
args:
55-
# - --strict
5665
- --ignore-missing-imports
5766
- --show-traceback
58-
additional_dependencies: [types-PyYAML>=6.0.12.9]
5967

6068
- repo: https://github.com/astral-sh/uv-pre-commit
6169
# uv version.

agent_assembly/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,26 @@ def __dir__() -> list[str]:
9595

9696

9797
if TYPE_CHECKING:
98-
from agent_assembly.adapters import FrameworkAdapter, GovernanceInterceptor
99-
from agent_assembly.core import AssemblyContext, init_assembly
98+
from agent_assembly.adapters import FrameworkAdapter as FrameworkAdapter
99+
from agent_assembly.adapters import GovernanceInterceptor as GovernanceInterceptor
100+
from agent_assembly.core import AssemblyContext as AssemblyContext
101+
from agent_assembly.core import init_assembly as init_assembly
100102
from agent_assembly.exceptions import (
101-
AdapterValidationError,
102-
AgentError,
103-
AssemblyError,
104-
ConfigurationError,
105-
GatewayError,
106-
MCPToolBlockedError,
107-
PolicyError,
108-
ToolExecutionBlockedError,
103+
AdapterValidationError as AdapterValidationError,
109104
)
110-
from agent_assembly.types import AuditEvent, CallStackNode, CallStackNodeKind
105+
from agent_assembly.exceptions import AgentError as AgentError
106+
from agent_assembly.exceptions import AssemblyError as AssemblyError
107+
from agent_assembly.exceptions import ConfigurationError as ConfigurationError
108+
from agent_assembly.exceptions import GatewayError as GatewayError
109+
from agent_assembly.exceptions import MCPToolBlockedError as MCPToolBlockedError
110+
from agent_assembly.exceptions import PolicyError as PolicyError
111+
from agent_assembly.exceptions import (
112+
ToolExecutionBlockedError as ToolExecutionBlockedError,
113+
)
114+
from agent_assembly.types import AuditEvent as AuditEvent
115+
from agent_assembly.types import CallStackNode as CallStackNode
116+
from agent_assembly.types import CallStackNodeKind as CallStackNodeKind
111117

112118
with contextlib.suppress(ImportError):
113-
from agent_assembly._core import (
114-
GovernanceEvent,
115-
RuntimeClient,
116-
)
119+
from agent_assembly._core import GovernanceEvent as GovernanceEvent
120+
from agent_assembly._core import RuntimeClient as RuntimeClient

agent_assembly/adapters/crewai/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import importlib
5+
import importlib as importlib
66
from collections.abc import Mapping
77
from dataclasses import dataclass
88
from functools import wraps

agent_assembly/adapters/google_adk/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import importlib
5+
import importlib as importlib
66
import inspect
77
from collections.abc import Mapping
88
from dataclasses import dataclass

agent_assembly/adapters/mcp/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import importlib
5+
import importlib as importlib
66
import importlib.util
77
import inspect
88
from dataclasses import dataclass

agent_assembly/adapters/openai_agents/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import importlib
5+
import importlib as importlib
66
import importlib.util
77
import inspect
88
from dataclasses import dataclass, field

agent_assembly/adapters/pydantic_ai/patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
import importlib
5+
import importlib as importlib
66
import inspect
77
from collections.abc import Mapping
88
from dataclasses import dataclass

agent_assembly/client/emitter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import threading
7+
from typing import Any
78

89
from agent_assembly.client.gateway import GatewayClient
910

@@ -21,7 +22,7 @@ def emit(
2122
source_agent_id: str,
2223
target_agent_id: str,
2324
edge_type: str,
24-
metadata: dict | None = None,
25+
metadata: dict[str, Any] | None = None,
2526
) -> None:
2627
"""Schedule a fire-and-forget edge report on a daemon thread."""
2728
t = threading.Thread(
@@ -36,7 +37,7 @@ def _send(
3637
source_agent_id: str,
3738
target_agent_id: str,
3839
edge_type: str,
39-
metadata: dict | None,
40+
metadata: dict[str, Any] | None,
4041
) -> None:
4142
try:
4243
self._client.report_edge(source_agent_id, target_agent_id, edge_type, metadata)

agent_assembly/client/gateway.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __exit__(self, *args: object) -> None:
9696
"""Context manager exit."""
9797
self.close()
9898

99-
async def register_agent(self) -> dict:
99+
async def register_agent(self) -> dict[str, Any]:
100100
"""
101101
Register the agent with the governance gateway.
102102
@@ -125,11 +125,12 @@ async def register_agent(self) -> dict:
125125
json=body if body else None,
126126
)
127127
response.raise_for_status()
128-
return response.json()
128+
data: dict[str, Any] = response.json()
129+
return data
129130
except httpx.HTTPError as e:
130131
raise GatewayError(f"Failed to register agent: {e}") from e
131132

132-
async def check_policy_compliance(self, action: str) -> dict:
133+
async def check_policy_compliance(self, action: str) -> dict[str, Any]:
133134
"""
134135
Check if an action complies with governance policies.
135136
@@ -148,7 +149,8 @@ async def check_policy_compliance(self, action: str) -> dict:
148149
json={"action": action},
149150
)
150151
response.raise_for_status()
151-
return response.json()
152+
data: dict[str, Any] = response.json()
153+
return data
152154
except httpx.HTTPError as e:
153155
raise GatewayError(f"Failed to check policy compliance: {e}") from e
154156

@@ -157,8 +159,8 @@ def report_edge(
157159
source_agent_id: str,
158160
target_agent_id: str,
159161
edge_type: str,
160-
metadata: dict | None = None,
161-
) -> dict:
162+
metadata: dict[str, Any] | None = None,
163+
) -> dict[str, Any]:
162164
"""
163165
Report a directed edge between two agents to the topology store.
164166
@@ -176,7 +178,7 @@ def report_edge(
176178
"""
177179
import json as _json
178180

179-
body: dict = {
181+
body: dict[str, str] = {
180182
"source_agent_id": source_agent_id,
181183
"target_agent_id": target_agent_id,
182184
"edge_type": edge_type,
@@ -186,7 +188,8 @@ def report_edge(
186188
try:
187189
response = self.client.post("/topology/edges", json=body)
188190
response.raise_for_status()
189-
return response.json()
191+
data: dict[str, Any] = response.json()
192+
return data
190193
except httpx.HTTPError as e:
191194
raise GatewayError(f"Failed to report edge: {e}") from e
192195

agent_assembly/core/assembly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class AssemblyContext:
7878
def __enter__(self) -> AssemblyContext:
7979
return self
8080

81-
def __exit__(self, exc_type: object, exc: object, tb: object) -> bool:
81+
def __exit__(self, exc_type: object, exc: object, tb: object) -> Literal[False]:
8282
del exc_type, exc, tb
8383
self.shutdown()
8484
return False

0 commit comments

Comments
 (0)