Skip to content

Commit e98c3cd

Browse files
committed
linting and format fixes from ruff
1 parent 10b7f3a commit e98c3cd

File tree

10 files changed

+31
-26
lines changed

10 files changed

+31
-26
lines changed

examples/basic/usage_tracking.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ async def main() -> None:
4343

4444
if __name__ == "__main__":
4545
asyncio.run(main())
46-

src/agents/extensions/memory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
21
"""Session memory backends living in the extensions namespace.
32
43
This package contains optional, production-grade session implementations that
54
introduce extra third-party dependencies (database drivers, ORMs, etc.). They
65
conform to the :class:`agents.memory.session.Session` protocol so they can be
76
used as a drop-in replacement for :class:`agents.memory.session.SQLiteSession`.
87
"""
8+
99
from __future__ import annotations
1010

1111
from .sqlalchemy_session import SQLAlchemySession # noqa: F401

src/agents/extensions/models/litellm_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ def convert_message_to_openai(
366366
if message.role != "assistant":
367367
raise ModelBehaviorError(f"Unsupported role: {message.role}")
368368

369-
tool_calls: list[
370-
ChatCompletionMessageFunctionToolCall | ChatCompletionMessageCustomToolCall
371-
] | None = (
369+
tool_calls: (
370+
list[ChatCompletionMessageFunctionToolCall | ChatCompletionMessageCustomToolCall] | None
371+
) = (
372372
[LitellmConverter.convert_tool_call_to_openai(tool) for tool in message.tool_calls]
373373
if message.tool_calls
374374
else None

src/agents/models/chatcmpl_converter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,7 @@ def extract_all_content(
272272
f"Only file_data is supported for input_file {casted_file_param}"
273273
)
274274
if "filename" not in casted_file_param or not casted_file_param["filename"]:
275-
raise UserError(
276-
f"filename must be provided for input_file {casted_file_param}"
277-
)
275+
raise UserError(f"filename must be provided for input_file {casted_file_param}")
278276
out.append(
279277
File(
280278
type="file",

src/agents/realtime/model_events.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class RealtimeModelInputAudioTranscriptionCompletedEvent:
8484

8585
type: Literal["input_audio_transcription_completed"] = "input_audio_transcription_completed"
8686

87+
8788
@dataclass
8889
class RealtimeModelInputAudioTimeoutTriggeredEvent:
8990
"""Input audio timeout triggered."""
@@ -94,6 +95,7 @@ class RealtimeModelInputAudioTimeoutTriggeredEvent:
9495

9596
type: Literal["input_audio_timeout_triggered"] = "input_audio_timeout_triggered"
9697

98+
9799
@dataclass
98100
class RealtimeModelTranscriptDeltaEvent:
99101
"""Partial transcript update."""

src/agents/realtime/openai_realtime.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,7 @@ async def _handle_ws_event(self, event: dict[str, Any]):
490490
try:
491491
if "previous_item_id" in event and event["previous_item_id"] is None:
492492
event["previous_item_id"] = "" # TODO (rm) remove
493-
parsed: AllRealtimeServerEvents = self._server_event_type_adapter.validate_python(
494-
event
495-
)
493+
parsed: AllRealtimeServerEvents = self._server_event_type_adapter.validate_python(event)
496494
except pydantic.ValidationError as e:
497495
logger.error(f"Failed to validate server event: {event}", exc_info=True)
498496
await self._emit_event(
@@ -583,11 +581,13 @@ async def _handle_ws_event(self, event: dict[str, Any]):
583581
):
584582
await self._handle_output_item(parsed.item)
585583
elif parsed.type == "input_audio_buffer.timeout_triggered":
586-
await self._emit_event(RealtimeModelInputAudioTimeoutTriggeredEvent(
587-
item_id=parsed.item_id,
588-
audio_start_ms=parsed.audio_start_ms,
589-
audio_end_ms=parsed.audio_end_ms,
590-
))
584+
await self._emit_event(
585+
RealtimeModelInputAudioTimeoutTriggeredEvent(
586+
item_id=parsed.item_id,
587+
audio_start_ms=parsed.audio_start_ms,
588+
audio_end_ms=parsed.audio_end_ms,
589+
)
590+
)
591591

592592
def _update_created_session(self, session: OpenAISessionObject) -> None:
593593
self._created_session = session

src/agents/run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,4 +1467,3 @@ def _copy_str_or_list(input: str | list[TResponseInputItem]) -> str | list[TResp
14671467
if isinstance(input, str):
14681468
return input
14691469
return input.copy()
1470-

tests/test_agent_instructions_signature.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def mock_run_context(self):
1616
@pytest.mark.asyncio
1717
async def test_valid_async_signature_passes(self, mock_run_context):
1818
"""Test that async function with correct signature works"""
19+
1920
async def valid_instructions(context, agent):
2021
return "Valid async instructions"
2122

@@ -26,6 +27,7 @@ async def valid_instructions(context, agent):
2627
@pytest.mark.asyncio
2728
async def test_valid_sync_signature_passes(self, mock_run_context):
2829
"""Test that sync function with correct signature works"""
30+
2931
def valid_instructions(context, agent):
3032
return "Valid sync instructions"
3133

@@ -36,6 +38,7 @@ def valid_instructions(context, agent):
3638
@pytest.mark.asyncio
3739
async def test_one_parameter_raises_error(self, mock_run_context):
3840
"""Test that function with only one parameter raises TypeError"""
41+
3942
def invalid_instructions(context):
4043
return "Should fail"
4144

@@ -50,6 +53,7 @@ def invalid_instructions(context):
5053
@pytest.mark.asyncio
5154
async def test_three_parameters_raises_error(self, mock_run_context):
5255
"""Test that function with three parameters raises TypeError"""
56+
5357
def invalid_instructions(context, agent, extra):
5458
return "Should fail"
5559

@@ -64,6 +68,7 @@ def invalid_instructions(context, agent, extra):
6468
@pytest.mark.asyncio
6569
async def test_zero_parameters_raises_error(self, mock_run_context):
6670
"""Test that function with no parameters raises TypeError"""
71+
6772
def invalid_instructions():
6873
return "Should fail"
6974

@@ -78,6 +83,7 @@ def invalid_instructions():
7883
@pytest.mark.asyncio
7984
async def test_function_with_args_kwargs_fails(self, mock_run_context):
8085
"""Test that function with *args/**kwargs fails validation"""
86+
8187
def flexible_instructions(context, agent, *args, **kwargs):
8288
return "Flexible instructions"
8389

tests/test_agent_runner.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from __future__ import annotations
22

33
import json
4+
import tempfile
5+
from pathlib import Path
46
from typing import Any
7+
from unittest.mock import patch
58

69
import pytest
710
from typing_extensions import TypedDict
@@ -20,6 +23,7 @@
2023
RunConfig,
2124
RunContextWrapper,
2225
Runner,
26+
SQLiteSession,
2327
UserError,
2428
handoff,
2529
)
@@ -36,11 +40,6 @@
3640
get_text_message,
3741
)
3842

39-
import tempfile
40-
from pathlib import Path
41-
from agents import SQLiteSession
42-
from unittest.mock import patch
43-
4443

4544
@pytest.mark.asyncio
4645
async def test_simple_first_run():

tests/test_session.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ async def test_session_memory_rejects_both_session_and_list_input(runner_method)
399399

400400
session.close()
401401

402+
402403
@pytest.mark.asyncio
403404
async def test_sqlite_session_unicode_content():
404405
"""Test that session correctly stores and retrieves unicode/non-ASCII content."""
@@ -437,9 +438,7 @@ async def test_sqlite_session_special_characters_and_sql_injection():
437438
items: list[TResponseInputItem] = [
438439
{"role": "user", "content": "O'Reilly"},
439440
{"role": "assistant", "content": "DROP TABLE sessions;"},
440-
{"role": "user", "content": (
441-
'"SELECT * FROM users WHERE name = \"admin\";"'
442-
)},
441+
{"role": "user", "content": ('"SELECT * FROM users WHERE name = "admin";"')},
443442
{"role": "assistant", "content": "Robert'); DROP TABLE students;--"},
444443
{"role": "user", "content": "Normal message"},
445444
]
@@ -450,17 +449,19 @@ async def test_sqlite_session_special_characters_and_sql_injection():
450449
assert len(retrieved) == len(items)
451450
assert retrieved[0].get("content") == "O'Reilly"
452451
assert retrieved[1].get("content") == "DROP TABLE sessions;"
453-
assert retrieved[2].get("content") == '"SELECT * FROM users WHERE name = \"admin\";"'
452+
assert retrieved[2].get("content") == '"SELECT * FROM users WHERE name = "admin";"'
454453
assert retrieved[3].get("content") == "Robert'); DROP TABLE students;--"
455454
assert retrieved[4].get("content") == "Normal message"
456455
session.close()
457456

457+
458458
@pytest.mark.asyncio
459459
async def test_sqlite_session_concurrent_access():
460460
"""
461461
Test concurrent access to the same session to verify data integrity.
462462
"""
463463
import concurrent.futures
464+
464465
with tempfile.TemporaryDirectory() as temp_dir:
465466
db_path = Path(temp_dir) / "test_concurrent.db"
466467
session_id = "concurrent_test"
@@ -477,6 +478,7 @@ def add_item(item):
477478
asyncio.set_event_loop(loop)
478479
loop.run_until_complete(session.add_items([item]))
479480
loop.close()
481+
480482
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
481483
executor.map(add_item, items)
482484

0 commit comments

Comments
 (0)