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

@@ -76,7 +76,7 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]):
ReceiveNotificationT
]""",
on_complete: Callable[["RequestResponder[ReceiveRequestT, SendResultT]"], Any],
) -> None:
):
self.request_id = request_id
self.request_meta = request_meta
self.request = request
@@ -95,7 +95,7 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]):
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None:
):
"""Exit the context manager, performing cleanup and notifying completion."""
try:
if self._completed:
@@ -103,7 +103,7 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]):
finally:
self._entered = False
def respond(self, response: SendResultT | ErrorData) -> None:
def respond(self, response: SendResultT | ErrorData):
"""Send a response for this request.
Must be called within a context manager block.
@@ -119,7 +119,7 @@ class RequestResponder(Generic[ReceiveRequestT, SendResultT]):
self._session._send_response(request_id=self.request_id, response=response)
def cancel(self) -> None:
def cancel(self):
"""Cancel this request and mark it as completed."""
if not self._entered:
raise RuntimeError("RequestResponder must be used as a context manager")
@@ -163,7 +163,7 @@ class BaseSession(
receive_notification_type: type[ReceiveNotificationT],
# If none, reading will never time out
read_timeout_seconds: timedelta | None = None,
) -> None:
):
self._read_stream = read_stream
self._write_stream = write_stream
self._response_streams = {}
@@ -183,7 +183,7 @@ class BaseSession(
self._receiver_future = self._executor.submit(self._receive_loop)
return self
def check_receiver_status(self) -> None:
def check_receiver_status(self):
"""`check_receiver_status` ensures that any exceptions raised during the
execution of `_receive_loop` are retrieved and propagated."""
if self._receiver_future and self._receiver_future.done():
@@ -191,7 +191,7 @@ class BaseSession(
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None:
):
self._read_stream.put(None)
self._write_stream.put(None)
@@ -277,7 +277,7 @@ class BaseSession(
self,
notification: SendNotificationT,
related_request_id: RequestId | None = None,
) -> None:
):
"""
Emits a notification, which is a one-way message that does not expect
a response.
@@ -296,7 +296,7 @@ class BaseSession(
)
self._write_stream.put(session_message)
def _send_response(self, request_id: RequestId, response: SendResultT | ErrorData) -> None:
def _send_response(self, request_id: RequestId, response: SendResultT | ErrorData):
if isinstance(response, ErrorData):
jsonrpc_error = JSONRPCError(jsonrpc="2.0", id=request_id, error=response)
session_message = SessionMessage(message=JSONRPCMessage(jsonrpc_error))
@@ -310,7 +310,7 @@ class BaseSession(
session_message = SessionMessage(message=JSONRPCMessage(jsonrpc_response))
self._write_stream.put(session_message)
def _receive_loop(self) -> None:
def _receive_loop(self):
"""
Main message processing loop.
In a real synchronous implementation, this would likely run in a separate thread.
@@ -382,7 +382,7 @@ class BaseSession(
logger.exception("Error in message processing loop")
raise
def _received_request(self, responder: RequestResponder[ReceiveRequestT, SendResultT]) -> None:
def _received_request(self, responder: RequestResponder[ReceiveRequestT, SendResultT]):
"""
Can be overridden by subclasses to handle a request without needing to
listen on the message stream.
@@ -391,15 +391,13 @@ class BaseSession(
forwarded on to the message stream.
"""
def _received_notification(self, notification: ReceiveNotificationT) -> None:
def _received_notification(self, notification: ReceiveNotificationT):
"""
Can be overridden by subclasses to handle a notification without needing
to listen on the message stream.
"""
def send_progress_notification(
self, progress_token: str | int, progress: float, total: float | None = None
) -> None:
def send_progress_notification(self, progress_token: str | int, progress: float, total: float | None = None):
"""
Sends a progress notification for a request that is currently being
processed.
@@ -408,5 +406,5 @@ class BaseSession(
def _handle_incoming(
self,
req: RequestResponder[ReceiveRequestT, SendResultT] | ReceiveNotificationT | Exception,
) -> None:
):
"""A generic handler for incoming messages. Overwritten by subclasses."""

View File

@@ -28,19 +28,19 @@ class LoggingFnT(Protocol):
def __call__(
self,
params: types.LoggingMessageNotificationParams,
) -> None: ...
): ...
class MessageHandlerFnT(Protocol):
def __call__(
self,
message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
) -> None: ...
): ...
def _default_message_handler(
message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
) -> None:
):
if isinstance(message, Exception):
raise ValueError(str(message))
elif isinstance(message, (types.ServerNotification | RequestResponder)):
@@ -68,7 +68,7 @@ def _default_list_roots_callback(
def _default_logging_callback(
params: types.LoggingMessageNotificationParams,
) -> None:
):
pass
@@ -94,7 +94,7 @@ class ClientSession(
logging_callback: LoggingFnT | None = None,
message_handler: MessageHandlerFnT | None = None,
client_info: types.Implementation | None = None,
) -> None:
):
super().__init__(
read_stream,
write_stream,
@@ -155,9 +155,7 @@ class ClientSession(
types.EmptyResult,
)
def send_progress_notification(
self, progress_token: str | int, progress: float, total: float | None = None
) -> None:
def send_progress_notification(self, progress_token: str | int, progress: float, total: float | None = None):
"""Send a progress notification."""
self.send_notification(
types.ClientNotification(
@@ -314,7 +312,7 @@ class ClientSession(
types.ListToolsResult,
)
def send_roots_list_changed(self) -> None:
def send_roots_list_changed(self):
"""Send a roots/list_changed notification."""
self.send_notification(
types.ClientNotification(
@@ -324,7 +322,7 @@ class ClientSession(
)
)
def _received_request(self, responder: RequestResponder[types.ServerRequest, types.ClientResult]) -> None:
def _received_request(self, responder: RequestResponder[types.ServerRequest, types.ClientResult]):
ctx = RequestContext[ClientSession, Any](
request_id=responder.request_id,
meta=responder.request_meta,
@@ -352,11 +350,11 @@ class ClientSession(
def _handle_incoming(
self,
req: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
) -> None:
):
"""Handle incoming messages by forwarding to the message handler."""
self._message_handler(req)
def _received_notification(self, notification: types.ServerNotification) -> None:
def _received_notification(self, notification: types.ServerNotification):
"""Handle notifications from the server."""
# Process specific notification types
match notification.root: