Refactor protocol and transport modules to use type hints for improved clarity and consistency

- Updated Codec class to use abstract methods for encoding and decoding envelopes.
- Changed Envelope class to use Dict and Optional for payload and error fields.
- Refined error handling in RPCError class with Optional type hints for details.
- Enhanced manifest validation logic with type hints for better type safety.
- Improved plugin loading mechanism with consistent type annotations.
- Updated RPCClient to utilize Optional for codec and connection attributes.
- Refactored transport classes to use Optional for server attributes and socket paths.
This commit is contained in:
DrSmoothl
2026-03-11 00:07:13 +08:00
parent 7f1e79ea28
commit 69219e36f7
19 changed files with 273 additions and 253 deletions

View File

@@ -4,6 +4,8 @@
绑定到 127.0.0.1 避免远程访问,但仍需会话令牌做身份校验。
"""
from typing import Optional
import asyncio
from .base import Connection, ConnectionHandler, TransportClient, TransportServer
@@ -20,7 +22,7 @@ class TCPTransportServer(TransportServer):
def __init__(self, host: str = "127.0.0.1", port: int = 0):
self._host = host
self._port = port # 0 表示自动分配
self._server: asyncio.AbstractServer | None = None
self._server: Optional[asyncio.AbstractServer] = None
self._actual_port: int = 0
async def start(self, handler: ConnectionHandler) -> None: