refactor: remove redundant comments and docstrings (#6527)

* refactor: remove redundant comments and docstrings

* fix(signal): annotate async context manager as a generator
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-30 13:07:03 +08:00
1 parent cb3ba45317
commit a4d2430140
922 files changed
+406 -7738

No files matched your search

+2 -52
View File
@@ -1,5 +1,3 @@
"""Tests for the shared openai_responses converters and parsers."""
import json
from io import StringIO
from types import SimpleNamespace
@@ -62,10 +60,6 @@ async def test_sdk_tool_alias_survives_capture_and_next_request_replay():
assert items[0]["async"] is True
assert "async_" not in items[0]
# ======================================================================
# converters - split_tool_call_id
# ======================================================================
class TestSplitToolCallId:
def test_plain_id(self):
@@ -87,11 +81,6 @@ class TestSplitToolCallId:
assert split_tool_call_id(42) == ("call_0", None)
# ======================================================================
# converters - convert_user_message
# ======================================================================
class TestConvertUserMessage:
def test_string_content(self):
result = convert_user_message("hello")
@@ -131,7 +120,6 @@ class TestConvertUserMessage:
assert result["content"] == [{"type": "input_text", "text": ""}]
def test_meta_fields_not_leaked(self):
"""_meta on content blocks must never appear in converted output."""
result = convert_user_message([
{"type": "text", "text": "hi", "_meta": {"path": "/tmp/x"}},
])
@@ -142,11 +130,6 @@ class TestConvertUserMessage:
assert result["content"] == [{"type": "input_text", "text": ""}]
# ======================================================================
# converters - convert_messages
# ======================================================================
class TestConvertMessages:
def test_system_extracted_as_instructions(self):
msgs = [
@@ -275,7 +258,6 @@ class TestConvertMessages:
assert items[1]["call_id"] == "call_1"
def test_assistant_with_tool_calls_no_id(self):
"""Fallback call IDs still work when tool_call.id is missing."""
_, items = convert_messages([{
"role": "assistant",
"content": None,
@@ -360,7 +342,6 @@ class TestConvertMessages:
assert items[0]["output"] == json.dumps(content, ensure_ascii=False)
def test_non_standard_keys_not_leaked(self):
"""Extra keys on messages must not appear in converted items."""
_, items = convert_messages([{
"role": "user",
"content": "hi",
@@ -372,7 +353,6 @@ class TestConvertMessages:
assert "_meta" not in str(item)
def test_full_conversation_roundtrip(self):
"""System + user + assistant(tool_call) + tool -> correct structure."""
msgs = [
{"role": "system", "content": "Be concise."},
{"role": "user", "content": "Weather in SF?"},
@@ -387,17 +367,12 @@ class TestConvertMessages:
]
instructions, items = convert_messages(msgs)
assert instructions == "Be concise."
assert len(items) == 3 # user, function_call, function_call_output
assert len(items) == 3
assert items[0]["role"] == "user"
assert items[1]["type"] == "function_call"
assert items[2]["type"] == "function_call_output"
# ======================================================================
# converters - convert_tools
# ======================================================================
class TestConvertTools:
def test_standard_function_tool(self):
tools = [{"type": "function", "function": {
@@ -440,7 +415,6 @@ class TestConvertTools:
assert convert_tools(tools) == []
def test_tool_without_function_wrapper(self):
"""Direct dict without type=function wrapper."""
tools = [{"name": "f1", "description": "d", "parameters": {}}]
result = convert_tools(tools)
assert result[0]["name"] == "f1"
@@ -459,11 +433,6 @@ class TestConvertTools:
assert len(convert_tools(tools)) == 2
# ======================================================================
# parsing - map_finish_reason
# ======================================================================
class TestMapFinishReason:
def test_completed(self):
assert map_finish_reason("completed") == "stop"
@@ -495,11 +464,6 @@ class TestMapFinishReason:
assert is_replayable_finish_reason(finish_reason) is False
# ======================================================================
# parsing - parse_response_output
# ======================================================================
class TestParseResponseOutput:
def test_text_response(self):
resp = {
@@ -562,7 +526,6 @@ class TestParseResponseOutput:
assert result.provider_state is not None
def test_malformed_tool_arguments_logged(self):
"""Malformed JSON arguments should log a warning and remain non-object."""
resp = {
"output": [{
"type": "function_call",
@@ -669,7 +632,6 @@ class TestParseResponseOutput:
assert result.provider_state is None
def test_sdk_model_object(self):
"""parse_response_output should handle SDK objects with model_dump()."""
mock = MagicMock()
mock.model_dump.return_value = {
"output": [{"type": "message", "role": "assistant",
@@ -1040,19 +1002,13 @@ class TestResponsesConversationState:
assert instructions == "You are KITT."
assert replayed is True
reasoning_items = [item for item in items if item.get("type") == "reasoning"]
assert len(reasoning_items) == 2 # one replayed, one converted delta
assert len(reasoning_items) == 2
assert isinstance(reasoning_items[0]["content"], list)
# Stored replay items keep their original block type.
assert reasoning_items[0]["content"][0]["type"] == "output_text"
assert isinstance(reasoning_items[1]["content"], list)
assert reasoning_items[1]["content"][0]["type"] == "reasoning_text"
# ======================================================================
# parsing - consume_sse
# ======================================================================
class _SseResponse:
def __init__(self, events: list[dict]):
self._events = events
@@ -1670,11 +1626,6 @@ class TestConsumeSse:
assert type(tool_calls[0].arguments) is type(arguments)
# ======================================================================
# parsing - consume_sdk_stream
# ======================================================================
class TestConsumeSdkStream:
@pytest.mark.asyncio
@pytest.mark.parametrize("event_type", ["response.output_text.delta", "response.refusal.delta"])
@@ -2205,7 +2156,6 @@ class TestConsumeSdkStream:
@pytest.mark.asyncio
async def test_malformed_tool_args_logged(self):
"""Malformed JSON in streaming tool args should log a warning and remain non-object."""
item_added = MagicMock(type="function_call", call_id="c1", id="fc1", arguments="")
item_added.name = "f"
ev1 = MagicMock(type="response.output_item.added", item=item_added)