style: 统一代码风格并进行现代化改进
对整个代码库进行了一次全面的风格统一和现代化改进。主要变更包括:
- 将 `hasattr` 等内置函数中的字符串参数从单引号 `'` 统一为双引号 `"`。
- 采用现代类型注解,例如将 `Optional[T]` 替换为 `T | None`,`List[T]` 替换为 `list[T]` 等。
- 移除不再需要的 Python 2 兼容性声明 `# -*- coding: utf-8 -*-`。
- 清理了多余的空行、注释和未使用的导入。
- 统一了文件末尾的换行符。
- 优化了部分日志输出和字符串格式化 (`f"{e!s}"`)。
这些改动旨在提升代码的可读性、一致性和可维护性,使其更符合现代 Python 编码规范。
This commit is contained in:
8
bot.py
8
bot.py
@@ -103,7 +103,7 @@ async def graceful_shutdown(main_system_instance):
|
||||
logger.info("正在优雅关闭麦麦...")
|
||||
|
||||
# 停止MainSystem中的组件,它会处理服务器等
|
||||
if main_system_instance and hasattr(main_system_instance, 'shutdown'):
|
||||
if main_system_instance and hasattr(main_system_instance, "shutdown"):
|
||||
logger.info("正在关闭MainSystem...")
|
||||
await main_system_instance.shutdown()
|
||||
|
||||
@@ -111,7 +111,7 @@ async def graceful_shutdown(main_system_instance):
|
||||
try:
|
||||
from src.chat.message_receive.chat_stream import get_chat_manager
|
||||
chat_manager = get_chat_manager()
|
||||
if hasattr(chat_manager, '_stop_auto_save'):
|
||||
if hasattr(chat_manager, "_stop_auto_save"):
|
||||
logger.info("正在停止聊天管理器...")
|
||||
chat_manager._stop_auto_save()
|
||||
except Exception as e:
|
||||
@@ -120,7 +120,7 @@ async def graceful_shutdown(main_system_instance):
|
||||
# 停止情绪管理器
|
||||
try:
|
||||
from src.mood.mood_manager import mood_manager
|
||||
if hasattr(mood_manager, 'stop'):
|
||||
if hasattr(mood_manager, "stop"):
|
||||
logger.info("正在停止情绪管理器...")
|
||||
await mood_manager.stop()
|
||||
except Exception as e:
|
||||
@@ -129,7 +129,7 @@ async def graceful_shutdown(main_system_instance):
|
||||
# 停止记忆系统
|
||||
try:
|
||||
from src.chat.memory_system.memory_manager import memory_manager
|
||||
if hasattr(memory_manager, 'shutdown'):
|
||||
if hasattr(memory_manager, "shutdown"):
|
||||
logger.info("正在停止记忆系统...")
|
||||
await memory_manager.shutdown()
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user