From 3235e7bae801f19507cda9fe066a2c25658cd5ea Mon Sep 17 00:00:00 2001 From: K2cr2O1 <2221577113@qq.com> Date: Fri, 9 Jan 2026 00:49:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(handler):=20=E7=A7=BB=E9=99=A4TYPE=5FC?= =?UTF-8?q?HECKING=E5=B9=B6=E7=9B=B4=E6=8E=A5=E5=AF=BC=E5=85=A5Bot?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化类型注解,直接导入Bot类而非使用TYPE_CHECKING条件导入,提高代码可读性和维护性 --- core/handlers/event_handler.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/handlers/event_handler.py b/core/handlers/event_handler.py index b188eca..50125cd 100644 --- a/core/handlers/event_handler.py +++ b/core/handlers/event_handler.py @@ -6,10 +6,9 @@ """ import inspect from abc import ABC, abstractmethod -from typing import Any, Callable, Dict, List, Optional, Tuple, TYPE_CHECKING +from typing import Any, Callable, Dict, List, Optional, Tuple -if TYPE_CHECKING: - from ..bot import Bot +from ..bot import Bot from ..config_loader import global_config from ..permission import Permission from ..utils.executor import run_in_thread_pool @@ -23,7 +22,7 @@ class BaseHandler(ABC): self.handlers: List[Dict[str, Any]] = [] @abstractmethod - async def handle(self, bot: "Bot", event: Any): + async def handle(self, bot: Bot, event: Any): """ 处理事件 """ @@ -32,7 +31,7 @@ class BaseHandler(ABC): async def _run_handler( self, func: Callable, - bot: "Bot", + bot: Bot, event: Any, args: Optional[List[str]] = None, permission_granted: Optional[bool] = None @@ -123,7 +122,7 @@ class MessageHandler(BaseHandler): return func return decorator - async def handle(self, bot: "Bot", event: Any): + async def handle(self, bot: Bot, event: Any): """ 处理消息事件,分发给命令处理器或通用消息处理器 """