AstrBot
AstrBot copied to clipboard
[Bug] core模块__init__.py存在副作用代码
What happened / 发生了什么
在原有实现中,astrbot.core 模块下的全局单例(如 astrbot_config, logger, db_helper, pip_installer 等)会在模块被 import 时立即初始化。这导致了以下问题:
- 启动副作用: 即使只是导入模块进行类型检查或单元测试,也会触发数据库连接、文件目录创建、日志配置等重量级操作。
- 循环导入风险: 模块顶层的即时初始化增加了与其他模块产生循环依赖的概率。
- 测试困难: 难以在不触发完整环境初始化的情况下对依赖该模块的代码进行隔离测试。
Reproduce / 如何复现?
创建一个测试脚本,仅包含import astrbot.core导入代码。 运行程序,工作区多余data目录
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
AstrBot version: 4.26.0-beta.12 git clone https://github.com/AstrBotDevs/AstrBot.git && cd AstrBot uv sync
OS
Linux
Logs / 报错日志
工作区多余额外目录 data
Are you willing to submit a PR? / 你愿意提交 PR 吗?
- [x] Yes!
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct。