diff --git a/bot.py b/bot.py index 4cdb54ede..aeec5d0d6 100644 --- a/bot.py +++ b/bot.py @@ -296,8 +296,10 @@ class DatabaseManager: # 使用线程执行器运行潜在的阻塞操作 await initialize_sql_database() elapsed_time = time.time() - start_time + + db_type = global_config.database.database_type if global_config else "unknown" logger.info( - f"数据库连接初始化成功,使用 {global_config.database.database_type} 数据库,耗时: {elapsed_time:.2f}秒" + f"数据库连接初始化成功,使用 {db_type} 数据库,耗时: {elapsed_time:.2f}秒" ) return self @@ -321,6 +323,10 @@ class ConfigurationValidator: try: from src.config.config import global_config + if global_config is None: + logger.error("全局配置未初始化") + return False + # 检查必要的配置节 required_sections = ["database", "bot"] for section in required_sections: diff --git a/src/__init__.py b/src/__init__.py index 907af17a3..0ac0c9576 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -8,7 +8,7 @@ from src.common.logger import get_logger egg = get_logger("小彩蛋") -def weighted_choice(data: Sequence[str], weights: list[float] | None = None) -> str: +def weighted_choice(data: Sequence[str], weights: Sequence[float] | None = None) -> str: """ 从 data 中按权重随机返回一条。 若 weights 为 None,则所有元素权重默认为 1。 diff --git a/src/main.py b/src/main.py index c5132f957..a6c437cea 100644 --- a/src/main.py +++ b/src/main.py @@ -7,7 +7,7 @@ import time import traceback from collections.abc import Callable, Coroutine from random import choices -from typing import Any +from typing import Any, cast from rich.traceback import install @@ -172,6 +172,9 @@ class MainSystem: logger.warning(f"{calc_name} 不是 BaseInterestCalculator 的有效子类") continue + # 显式转换类型以修复 Pyright 错误 + component_class = cast(type[BaseInterestCalculator], component_class) + # 创建组件实例 calculator_instance = component_class()