style: 统一代码风格并进行现代化改进
对整个代码库进行了一次全面的风格统一和现代化改进。主要变更包括:
- 将 `hasattr` 等内置函数中的字符串参数从单引号 `'` 统一为双引号 `"`。
- 采用现代类型注解,例如将 `Optional[T]` 替换为 `T | None`,`List[T]` 替换为 `list[T]` 等。
- 移除不再需要的 Python 2 兼容性声明 `# -*- coding: utf-8 -*-`。
- 清理了多余的空行、注释和未使用的导入。
- 统一了文件末尾的换行符。
- 优化了部分日志输出和字符串格式化 (`f"{e!s}"`)。
这些改动旨在提升代码的可读性、一致性和可维护性,使其更符合现代 Python 编码规范。
This commit is contained in:
committed by
Windpicker-owo
parent
1fb2ab6450
commit
cd84373828
@@ -313,11 +313,11 @@ class ChatStream:
|
||||
except Exception as e:
|
||||
logger.error(f"计算消息兴趣值失败: {e}", exc_info=True)
|
||||
# 异常情况下使用默认值
|
||||
if hasattr(db_message, 'interest_value'):
|
||||
if hasattr(db_message, "interest_value"):
|
||||
db_message.interest_value = 0.3
|
||||
if hasattr(db_message, 'should_reply'):
|
||||
if hasattr(db_message, "should_reply"):
|
||||
db_message.should_reply = False
|
||||
if hasattr(db_message, 'should_act'):
|
||||
if hasattr(db_message, "should_act"):
|
||||
db_message.should_act = False
|
||||
|
||||
def _extract_reply_from_segment(self, segment) -> str | None:
|
||||
@@ -894,10 +894,10 @@ def _convert_to_original_stream(self, optimized_stream) -> "ChatStream":
|
||||
original_stream.saved = optimized_stream.saved
|
||||
|
||||
# 复制上下文信息(如果存在)
|
||||
if hasattr(optimized_stream, '_stream_context') and optimized_stream._stream_context:
|
||||
if hasattr(optimized_stream, "_stream_context") and optimized_stream._stream_context:
|
||||
original_stream.stream_context = optimized_stream._stream_context
|
||||
|
||||
if hasattr(optimized_stream, '_context_manager') and optimized_stream._context_manager:
|
||||
if hasattr(optimized_stream, "_context_manager") and optimized_stream._context_manager:
|
||||
original_stream.context_manager = optimized_stream._context_manager
|
||||
|
||||
return original_stream
|
||||
|
||||
Reference in New Issue
Block a user