Skip to content

Commit 634ddce

Browse files
committed
linting
1 parent ed4997b commit 634ddce

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ ignore_missing_imports = true
183183
module = "grpc.*"
184184
ignore_missing_imports = true
185185

186+
[[tool.mypy.overrides]]
187+
module = "agents.*"
188+
ignore_missing_imports = true
189+
186190
#
187191
# Tool: Flake8
188192
#

sentry_sdk/integrations/openai_agents/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
def _patch_runner():
1717
# type: () -> None
18-
agents.Runner.run = _create_run_wrapper(agents.Runner.run) # type: ignore[method-assign]
19-
agents.Runner.run_sync = _create_run_wrapper(agents.Runner.run_sync) # type: ignore[method-assign]
20-
agents.Runner.run_streamed = _create_run_wrapper(agents.Runner.run_streamed) # type: ignore[method-assign]
18+
agents.Runner.run = _create_run_wrapper(agents.Runner.run)
19+
agents.Runner.run_sync = _create_run_wrapper(agents.Runner.run_sync)
20+
agents.Runner.run_streamed = _create_run_wrapper(agents.Runner.run_streamed)
2121

2222

2323
def _patch_model():
2424
# type: () -> None
25-
agents.Runner._get_model = _create_get_model_wrapper(agents.Runner._get_model) # type: ignore[method-assign]
25+
agents.Runner._get_model = _create_get_model_wrapper(agents.Runner._get_model)
2626

2727

2828
def _patch_tools():
2929
# type: () -> None
30-
agents.Runner._get_all_tools = _create_get_all_tools_wrapper( # type: ignore[method-assign]
30+
agents.Runner._get_all_tools = _create_get_all_tools_wrapper(
3131
agents.Runner._get_all_tools
3232
)
3333

sentry_sdk/integrations/openai_agents/patches/models.py

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

55
from ..spans import ai_client_span, update_ai_client_span
66

7+
from typing import TYPE_CHECKING
8+
9+
if TYPE_CHECKING:
10+
from typing import Any, Callable
11+
712

813
try:
914
import agents
@@ -12,6 +17,7 @@
1217

1318

1419
def _create_get_model_wrapper(original_get_model):
20+
# type: (Callable[..., Any]) -> Callable[..., Any]
1521
"""
1622
Wraps the agents.Runner._get_model method to wrap the get_response method of the model to create a AI client span.
1723
"""
@@ -26,6 +32,7 @@ def wrapped_get_model(cls, agent, run_config):
2632

2733
@wraps(original_get_response)
2834
async def wrapped_get_response(*args, **kwargs):
35+
# type: (*Any, **Any) -> Any
2936
with ai_client_span(agent, kwargs) as span:
3037
result = await original_get_response(*args, **kwargs)
3138
update_ai_client_span(span, agent, kwargs, result)

sentry_sdk/integrations/openai_agents/patches/runner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from typing import TYPE_CHECKING
1111

1212
if TYPE_CHECKING:
13-
from typing import Any
14-
from typing import Callable
13+
from typing import Any, Callable
1514

1615
try:
1716
import agents
@@ -20,7 +19,7 @@
2019

2120

2221
def _create_run_wrapper(original_func):
23-
# type: (Callable) -> Callable
22+
# type: (Callable[..., Any]) -> Callable[..., Any]
2423
"""
2524
Wraps the agents.Runner.run* methods to create a root span for the agent workflow runs.
2625
"""

sentry_sdk/integrations/openai_agents/patches/tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import TYPE_CHECKING
88

99
if TYPE_CHECKING:
10-
from typing import Any
10+
from typing import Any, Callable
1111

1212
try:
1313
import agents
@@ -16,6 +16,7 @@
1616

1717

1818
def _create_get_all_tools_wrapper(original_get_all_tools):
19+
# type: (Callable[..., Any]) -> Callable[..., Any]
1920
"""
2021
Wraps the agents.Runner._get_all_tools method of the Runner class to wrap all function tools with Sentry instrumentation.
2122
"""
@@ -39,6 +40,7 @@ async def wrapped_get_all_tools(cls, agent, context_wrapper):
3940
original_on_invoke = tool.on_invoke_tool
4041

4142
def create_wrapped_invoke(current_tool, current_on_invoke):
43+
# type: (agents.Tool, Callable[..., Any]) -> Callable[..., Any]
4244
@wraps(current_on_invoke)
4345
async def sentry_wrapped_on_invoke_tool(*args, **kwargs):
4446
# type: (*Any, **Any) -> Any

sentry_sdk/integrations/openai_agents/spans/agent_workflow.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
if TYPE_CHECKING:
77
from agents import Agent
8-
from sentry_sdk import Span
98
from typing import Any
109

1110

1211
def agent_workflow_span(*args, **kwargs):
13-
# type: (*Any, **Any) -> Span
12+
# type: (*Any, **Any) -> sentry_sdk.tracing.Span
1413
agent = args[0]
1514
# Create a transaction or a span if an transaction is already active
1615
span = _get_start_span_function()(
@@ -22,5 +21,5 @@ def agent_workflow_span(*args, **kwargs):
2221

2322

2423
def update_agent_workflow_span(span, agent, result):
25-
# type: (Span, Agent, Any) -> None
24+
# type: (sentry_sdk.tracing.Span, Agent, Any) -> None
2625
pass

sentry_sdk/integrations/openai_agents/spans/invoke_agent.py

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

1212

1313
def invoke_agent_span(context, agent):
14-
# type: (agents.RunContextWrapper, agents.Agent) -> None
14+
# type: (agents.RunContextWrapper, agents.Agent) -> sentry_sdk.tracing.Span
1515
span = sentry_sdk.start_span(
1616
op=OP.GEN_AI_INVOKE_AGENT,
1717
name=f"invoke_agent {agent.name}",

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def _create_hook_wrapper(original_hook, sentry_hook):
4444
# type: (Callable[..., Any], Callable[..., Any]) -> Callable[..., Any]
4545
@wraps(original_hook)
4646
async def async_wrapper(*args, **kwargs):
47+
# type: (*Any, **Any) -> Any
4748
await sentry_hook(*args, **kwargs)
4849
return await original_hook(*args, **kwargs)
4950

@@ -153,7 +154,7 @@ def _set_input_data(span, get_response_kwargs):
153154
"user": [],
154155
"assistant": [],
155156
"tool": [],
156-
}
157+
} # type: (dict[str, list[Any]])
157158
system_instructions = get_response_kwargs.get("system_instructions")
158159
if system_instructions:
159160
messages_by_role["system"].append({"type": "text", "text": system_instructions})
@@ -185,7 +186,7 @@ def _set_output_data(span, result):
185186
output_messages = {
186187
"response": [],
187188
"tool": [],
188-
}
189+
} # type: (dict[str, list[Any]])
189190

190191
for output in result.output:
191192
if output.type == "function_call":

0 commit comments

Comments
 (0)