chore: 代码格式化与类型注解优化
对项目中的多个文件进行了代码风格调整和类型注解更新。
- 使用 ruff 工具对代码进行自动格式化,主要包括:
- 统一 import 语句的顺序和风格。
- 移除未使用的 import。
- 调整代码间距和空行。
- 将部分 `Optional[str]` 和 `List[T]` 等旧式类型注解更新为现代的 `str | None` 和 `list[T]` 语法。
- 修复了一些小的代码风格问题,例如将 `f'...'` 更改为 `f"..."`。
This commit is contained in:
committed by
Windpicker-owo
parent
9380231019
commit
f1dfe64f88
@@ -198,7 +198,7 @@ class MessageStorage:
|
||||
async def replace_image_descriptions(text: str) -> str:
|
||||
"""异步地将文本中的所有[图片:描述]标记替换为[picid:image_id]"""
|
||||
pattern = r"\[图片:([^\]]+)\]"
|
||||
|
||||
|
||||
# 如果没有匹配项,提前返回以提高效率
|
||||
if not re.search(pattern, text):
|
||||
return text
|
||||
@@ -209,7 +209,7 @@ class MessageStorage:
|
||||
for match in re.finditer(pattern, text):
|
||||
# 添加上一个匹配到当前匹配之间的文本
|
||||
new_text.append(text[last_end:match.start()])
|
||||
|
||||
|
||||
description = match.group(1).strip()
|
||||
replacement = match.group(0) # 默认情况下,替换为原始匹配文本
|
||||
try:
|
||||
@@ -236,7 +236,7 @@ class MessageStorage:
|
||||
|
||||
# 添加最后一个匹配到字符串末尾的文本
|
||||
new_text.append(text[last_end:])
|
||||
|
||||
|
||||
return "".join(new_text)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user