remove bare list, dict, Sequence, None, Any (#25058)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
Asuka Minato
2025-09-06 04:32:23 +09:00
committed by GitHub
parent 2b0695bdde
commit a78339a040
306 changed files with 787 additions and 817 deletions

View File

@@ -47,7 +47,7 @@ class SSETransport:
headers: dict[str, Any] | None = None,
timeout: float = 5.0,
sse_read_timeout: float = 5 * 60,
) -> None:
):
"""Initialize the SSE transport.
Args:
@@ -76,7 +76,7 @@ class SSETransport:
return url_parsed.netloc == endpoint_parsed.netloc and url_parsed.scheme == endpoint_parsed.scheme
def _handle_endpoint_event(self, sse_data: str, status_queue: StatusQueue) -> None:
def _handle_endpoint_event(self, sse_data: str, status_queue: StatusQueue):
"""Handle an 'endpoint' SSE event.
Args:
@@ -94,7 +94,7 @@ class SSETransport:
status_queue.put(_StatusReady(endpoint_url))
def _handle_message_event(self, sse_data: str, read_queue: ReadQueue) -> None:
def _handle_message_event(self, sse_data: str, read_queue: ReadQueue):
"""Handle a 'message' SSE event.
Args:
@@ -110,7 +110,7 @@ class SSETransport:
logger.exception("Error parsing server message")
read_queue.put(exc)
def _handle_sse_event(self, sse: ServerSentEvent, read_queue: ReadQueue, status_queue: StatusQueue) -> None:
def _handle_sse_event(self, sse: ServerSentEvent, read_queue: ReadQueue, status_queue: StatusQueue):
"""Handle a single SSE event.
Args:
@@ -126,7 +126,7 @@ class SSETransport:
case _:
logger.warning("Unknown SSE event: %s", sse.event)
def sse_reader(self, event_source: EventSource, read_queue: ReadQueue, status_queue: StatusQueue) -> None:
def sse_reader(self, event_source: EventSource, read_queue: ReadQueue, status_queue: StatusQueue):
"""Read and process SSE events.
Args:
@@ -144,7 +144,7 @@ class SSETransport:
finally:
read_queue.put(None)
def _send_message(self, client: httpx.Client, endpoint_url: str, message: SessionMessage) -> None:
def _send_message(self, client: httpx.Client, endpoint_url: str, message: SessionMessage):
"""Send a single message to the server.
Args:
@@ -163,7 +163,7 @@ class SSETransport:
response.raise_for_status()
logger.debug("Client message sent successfully: %s", response.status_code)
def post_writer(self, client: httpx.Client, endpoint_url: str, write_queue: WriteQueue) -> None:
def post_writer(self, client: httpx.Client, endpoint_url: str, write_queue: WriteQueue):
"""Handle writing messages to the server.
Args:
@@ -303,7 +303,7 @@ def sse_client(
write_queue.put(None)
def send_message(http_client: httpx.Client, endpoint_url: str, session_message: SessionMessage) -> None:
def send_message(http_client: httpx.Client, endpoint_url: str, session_message: SessionMessage):
"""
Send a message to the server using the provided HTTP client.

View File

@@ -82,7 +82,7 @@ class StreamableHTTPTransport:
headers: dict[str, Any] | None = None,
timeout: float | timedelta = 30,
sse_read_timeout: float | timedelta = 60 * 5,
) -> None:
):
"""Initialize the StreamableHTTP transport.
Args:
@@ -122,7 +122,7 @@ class StreamableHTTPTransport:
def _maybe_extract_session_id_from_response(
self,
response: httpx.Response,
) -> None:
):
"""Extract and store session ID from response headers."""
new_session_id = response.headers.get(MCP_SESSION_ID)
if new_session_id:
@@ -173,7 +173,7 @@ class StreamableHTTPTransport:
self,
client: httpx.Client,
server_to_client_queue: ServerToClientQueue,
) -> None:
):
"""Handle GET stream for server-initiated messages."""
try:
if not self.session_id:
@@ -197,7 +197,7 @@ class StreamableHTTPTransport:
except Exception as exc:
logger.debug("GET stream error (non-fatal): %s", exc)
def _handle_resumption_request(self, ctx: RequestContext) -> None:
def _handle_resumption_request(self, ctx: RequestContext):
"""Handle a resumption request using GET with SSE."""
headers = self._update_headers_with_session(ctx.headers)
if ctx.metadata and ctx.metadata.resumption_token:
@@ -230,7 +230,7 @@ class StreamableHTTPTransport:
if is_complete:
break
def _handle_post_request(self, ctx: RequestContext) -> None:
def _handle_post_request(self, ctx: RequestContext):
"""Handle a POST request with response processing."""
headers = self._update_headers_with_session(ctx.headers)
message = ctx.session_message.message
@@ -278,7 +278,7 @@ class StreamableHTTPTransport:
self,
response: httpx.Response,
server_to_client_queue: ServerToClientQueue,
) -> None:
):
"""Handle JSON response from the server."""
try:
content = response.read()
@@ -288,7 +288,7 @@ class StreamableHTTPTransport:
except Exception as exc:
server_to_client_queue.put(exc)
def _handle_sse_response(self, response: httpx.Response, ctx: RequestContext) -> None:
def _handle_sse_response(self, response: httpx.Response, ctx: RequestContext):
"""Handle SSE response from the server."""
try:
event_source = EventSource(response)
@@ -307,7 +307,7 @@ class StreamableHTTPTransport:
self,
content_type: str,
server_to_client_queue: ServerToClientQueue,
) -> None:
):
"""Handle unexpected content type in response."""
error_msg = f"Unexpected content type: {content_type}"
logger.error(error_msg)
@@ -317,7 +317,7 @@ class StreamableHTTPTransport:
self,
server_to_client_queue: ServerToClientQueue,
request_id: RequestId,
) -> None:
):
"""Send a session terminated error response."""
jsonrpc_error = JSONRPCError(
jsonrpc="2.0",
@@ -333,7 +333,7 @@ class StreamableHTTPTransport:
client_to_server_queue: ClientToServerQueue,
server_to_client_queue: ServerToClientQueue,
start_get_stream: Callable[[], None],
) -> None:
):
"""Handle writing requests to the server.
This method processes messages from the client_to_server_queue and sends them to the server.
@@ -379,7 +379,7 @@ class StreamableHTTPTransport:
except Exception as exc:
server_to_client_queue.put(exc)
def terminate_session(self, client: httpx.Client) -> None:
def terminate_session(self, client: httpx.Client):
"""Terminate the session by sending a DELETE request."""
if not self.session_id:
return
@@ -441,7 +441,7 @@ def streamablehttp_client(
timeout=httpx.Timeout(transport.timeout, read=transport.sse_read_timeout),
) as client:
# Define callbacks that need access to thread pool
def start_get_stream() -> None:
def start_get_stream():
"""Start a worker thread to handle server-initiated messages."""
executor.submit(transport.handle_get_stream, client, server_to_client_queue)