Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -34,7 +34,7 @@ def responses(request: Request) -> OpenAIServingResponses | None:
async def _convert_stream_to_sse_events(
generator: AsyncGenerator[StreamingResponsesResponse, None],
) -> AsyncGenerator[str, None]:
"""Convert the generator to a stream of events in SSE format"""
"""Convert the generator to a stream of events in SSE format."""
async for event in generator:
event_type = getattr(event, "type", "unknown")
# https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
+10 -11
View File
@@ -141,9 +141,7 @@ class ConversationContext(ABC):
def _create_json_parse_error_messages(
last_msg: Message, e: json.JSONDecodeError
) -> list[Message]:
"""
Creates an error message when json parse failed.
"""
"""Creates an error message when json parse failed."""
error_msg = (
f"Error parsing tool arguments as JSON: {str(e)}. "
"Please ensure the tool call arguments are valid JSON and try again."
@@ -161,7 +159,7 @@ def _create_json_parse_error_messages(
class SimpleContext(ConversationContext):
"""This is a context that cannot handle MCP tool calls"""
"""This is a context that cannot handle MCP tool calls."""
def __init__(
self,
@@ -410,7 +408,8 @@ class ParsableContext(ConversationContext):
def need_builtin_tool_call(self) -> bool:
"""Return true if the last message is a builtin tool call
that the request has enabled."""
that the request has enabled.
"""
last_message = self.response_messages[-1]
if last_message.type != "function_call":
return False
@@ -474,8 +473,7 @@ class ParsableContext(ConversationContext):
async def call_container_tool(
self, tool_session: Union["ClientSession", Tool], last_msg: Message
) -> list[Message]:
"""
Call container tool. Expect this to be run in a stateful docker
"""Call container tool. Expect this to be run in a stateful docker
with command line terminal.
The official container tool would at least
expect the following format:
@@ -583,7 +581,7 @@ class ParsableContext(ConversationContext):
exit_stack.push_async_exit(self.cleanup_session)
async def cleanup_session(self, *args, **kwargs) -> None:
"""Can be used as coro to used in __aexit__"""
"""Can be used as coro to used in __aexit__."""
async def cleanup_tool_session(tool_session):
if not isinstance(tool_session, Tool):
@@ -693,6 +691,7 @@ class HarmonyContext(ConversationContext):
Args:
output: The RequestOutput containing prompt token information
"""
if output.prompt_token_ids is not None:
this_turn_input_tokens = len(output.prompt_token_ids)
@@ -757,6 +756,7 @@ class HarmonyContext(ConversationContext):
Returns:
int: Number of output tokens processed in this call
"""
updated_output_token_count = 0
if output.outputs:
@@ -884,8 +884,7 @@ class HarmonyContext(ConversationContext):
async def call_container_tool(
self, tool_session: Union["ClientSession", Tool], last_msg: Message
) -> list[Message]:
"""
Call container tool. Expect this to be run in a stateful docker
"""Call container tool. Expect this to be run in a stateful docker
with command line terminal.
The official container tool would at least
expect the following format:
@@ -925,7 +924,7 @@ class HarmonyContext(ConversationContext):
]
async def cleanup_session(self, *args, **kwargs) -> None:
"""Can be used as coro to used in __aexit__"""
"""Can be used as coro to used in __aexit__."""
async def cleanup_tool_session(tool_session):
if not isinstance(tool_session, Tool):
+3 -3
View File
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Harmony ↔ Responses API conversion utilities.
"""Harmony ↔ Responses API conversion utilities.
Handles two directions:
1. Response Input → Harmony Messages (input parsing)
@@ -53,7 +52,8 @@ logger = init_logger(__name__)
def _parse_harmony_format_message(chat_msg: dict) -> Message:
"""Reconstruct a Message from Harmony-format dict,
preserving channel, recipient, and content_type."""
preserving channel, recipient, and content_type.
"""
author_dict = chat_msg["author"]
role = author_dict.get("role")
name = author_dict.get("name")
@@ -100,9 +100,7 @@ class ResponseUsage(OpenAIBaseModel):
def serialize_message(msg):
"""
Serializes a single message
"""
"""Serializes a single message."""
if isinstance(msg, dict):
return msg
elif hasattr(msg, "to_dict"):
@@ -113,15 +111,14 @@ def serialize_message(msg):
def serialize_messages(msgs):
"""
Serializes multiple messages
"""
"""Serializes multiple messages."""
return [serialize_message(msg) for msg in msgs] if msgs else None
class ResponseRawMessageAndToken(OpenAIBaseModel):
"""Class to show the raw message.
If message / tokens diverge, tokens is the source of truth"""
If message / tokens diverge, tokens is the source of truth
"""
message: str
tokens: list[int]
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""
Streaming SSE event builders for the Responses API.
"""Streaming SSE event builders for the Responses API.
Pure functions that translate streaming state + delta data into
OpenAI Response API SSE events. Used by the streaming event
@@ -125,8 +124,7 @@ def is_mcp_tool_by_namespace(
recipient: str | None,
allowed_function_tool_names: frozenset[str] | None = None,
) -> bool:
"""
Determine if a tool call is an MCP tool based on recipient prefix.
"""Determine if a tool call is an MCP tool based on recipient prefix.
Inverse of :func:`is_function_recipient` — everything that is not
a function call is an MCP tool.
@@ -1145,8 +1143,7 @@ def split_delta(delta: DeltaMessage) -> list[DeltaMessage]:
class SimpleStreamingEventProcessor:
"""
State-machine processor for the simple (non-Harmony) streaming path.
"""State-machine processor for the simple (non-Harmony) streaming path.
Core flow:
1. Resolve the target state from the delta_message
@@ -1188,8 +1185,7 @@ class SimpleStreamingEventProcessor:
def resolve_target_state(
self, delta_message: DeltaMessage
) -> tuple[_StateType, Any]:
"""
Decide which state the next delta belongs to.
"""Decide which state the next delta belongs to.
Priority: TOOL_CALL > REASONING > CONTENT, fallback to NONE.
For TOOL_CALL the first tool_call object is also returned so
@@ -1207,8 +1203,7 @@ class SimpleStreamingEventProcessor:
return _StateType.NONE, None
def needs_transition(self, target_state: _StateType, tool_call: Any) -> bool:
"""
Return True when we must close the current state and open a new one.
"""Return True when we must close the current state and open a new one.
Two cases trigger a transition:
1. The target state differs from the current state
+5 -9
View File
@@ -115,8 +115,7 @@ def build_response_output_items(
def should_continue_final_message(
request_input: str | list[ResponseInputOutputItem],
) -> bool:
"""
Determine if the last input message is a partial assistant message
"""Determine if the last input message is a partial assistant message
that should be continued rather than starting a new generation.
This enables partial message completion similar to Anthropic's Messages API,
@@ -132,6 +131,7 @@ def should_continue_final_message(
Returns:
True if the final message should be continued, False otherwise
"""
if isinstance(request_input, str):
# Simple string input is always a user message
@@ -226,8 +226,7 @@ def _construct_message_from_response_item(
item: ResponseInputOutputItem,
prev_msg: ChatCompletionMessageParam | None = None,
) -> ChatCompletionMessageParam | None:
"""
Returns a new message or None. If `None`, `prev_msg` might be updated.
"""Returns a new message or None. If `None`, `prev_msg` might be updated.
If `prev_msg` is `None`, a new message is always returned.
"""
prev_assistant_msg = (
@@ -360,9 +359,7 @@ def extract_function_tool_names(tools: list[Tool]) -> frozenset[str]:
def extract_tool_types(tools: list[Tool]) -> set[str]:
"""
Extracts the tool types from the given tools.
"""
"""Extracts the tool types from the given tools."""
tool_types: set[str] = set()
for tool in tools:
if tool.type == "mcp":
@@ -379,8 +376,7 @@ def extract_tool_types(tools: list[Tool]) -> set[str]:
def convert_tool_responses_to_completions_format(
tool: dict,
) -> ChatCompletionToolsParam:
"""
Convert a flat Responses tool schema:
"""Convert a flat Responses tool schema:
{"type": "function", "name": "...", "description": "...", "parameters": {...}}
into a Chat Completions tool param for chat-template rendering.
"""