插件系统代码风格修复

This commit is contained in:
DrSmoothl
2026-03-13 11:07:19 +08:00
parent bcb7963d37
commit 8ac0aff479
15 changed files with 55 additions and 47 deletions

View File

@@ -31,7 +31,7 @@ class CapabilityService:
4. 执行实际操作并返回结果
"""
def __init__(self, policy_engine: PolicyEngine):
def __init__(self, policy_engine: PolicyEngine) -> None:
self._policy = policy_engine
# capability_name -> implementation
self._implementations: Dict[str, CapabilityImpl] = {}

View File

@@ -11,10 +11,10 @@
from typing import Any, Dict, List, Optional
from src.common.logger import get_logger
import re
from src.common.logger import get_logger
logger = get_logger("plugin_runtime.host.component_registry")
@@ -32,7 +32,7 @@ class RegisteredComponent:
component_type: str,
plugin_id: str,
metadata: Dict[str, Any],
):
) -> None:
self.name = name
self.full_name = f"{plugin_id}.{name}"
self.component_type = component_type
@@ -57,7 +57,7 @@ class ComponentRegistry:
供业务层查询可用组件、匹配命令、调度 action/event 等。
"""
def __init__(self):
def __init__(self) -> None:
# 全量索引
self._components: Dict[str, RegisteredComponent] = {} # full_name -> comp

View File

@@ -22,7 +22,7 @@ class PolicyEngine:
管理所有插件的能力令牌,提供授权校验。
"""
def __init__(self):
def __init__(self) -> None:
self._tokens: Dict[str, CapabilityToken] = {}
def register_plugin(

View File

@@ -7,11 +7,11 @@
4. 优雅关停
"""
import logging as stdlib_logging
from typing import Any, Dict, List, Optional, Tuple
import asyncio
import contextlib
import logging as stdlib_logging
import os
import sys
@@ -559,9 +559,12 @@ class PluginSupervisor:
task.add_done_callback(
lambda done_task: None
if self._stderr_drain_task is not done_task
else setattr(self, "_stderr_drain_task", None)
else self._clear_stderr_drain_task()
)
def _clear_stderr_drain_task(self) -> None:
self._stderr_drain_task = None
async def _drain_runner_stderr(
self,
stream: asyncio.StreamReader,
@@ -578,8 +581,7 @@ class PluginSupervisor:
line = await stream.readline()
if not line:
break
message = line.decode(errors="replace").rstrip()
if message:
if message := line.decode(errors="replace").rstrip():
# 将 stderr 输出以 WARNING 级展示:
# 如果 Runner 正常运行,此流应当无输出;
# 有输出说明进程级错误发生,需要出现在主进程日志中

View File

@@ -54,7 +54,7 @@ class ModificationRecord:
"""消息修改记录"""
__slots__ = ("stage", "hook_name", "timestamp", "fields_changed")
def __init__(self, stage: str, hook_name: str, fields_changed: List[str]):
def __init__(self, stage: str, hook_name: str, fields_changed: List[str]) -> None:
self.stage = stage
self.hook_name = hook_name
self.timestamp = time.perf_counter()
@@ -64,7 +64,7 @@ class ModificationRecord:
class WorkflowContext:
"""Workflow 执行上下文"""
def __init__(self, trace_id: Optional[str] = None, stream_id: Optional[str] = None):
def __init__(self, trace_id: Optional[str] = None, stream_id: Optional[str] = None) -> None:
self.trace_id = trace_id or uuid.uuid4().hex
self.stream_id = stream_id
self.timings: Dict[str, float] = {}
@@ -92,7 +92,7 @@ class WorkflowResult:
return_message: str = "",
stopped_at: str = "",
diagnostics: Optional[Dict[str, Any]] = None,
):
) -> None:
self.status = status
self.return_message = return_message
self.stopped_at = stopped_at
@@ -109,7 +109,7 @@ class WorkflowExecutor:
实现 stage-based pipeline + per-stage hook chain with priority + early return。
"""
def __init__(self, registry: ComponentRegistry):
def __init__(self, registry: ComponentRegistry) -> None:
self._registry = registry
async def execute(