refactor(core): 优化类型提示与代码风格
本次提交对项目代码进行了广泛的重构,主要集中在以下几个方面:
1. **类型提示现代化**:
- 将 `typing` 模块中的 `Optional[T]`、`List[T]`、`Dict[K, V]` 等旧式类型提示更新为现代的 `T | None`、`list[T]`、`dict[K, V]` 语法。
- 这提高了代码的可读性,并与较新 Python 版本的风格保持一致。
2. **代码风格统一**:
- 移除了多余的空行和不必要的空格,使代码更加紧凑和规范。
- 统一了部分日志输出的格式,增强了日志的可读性。
3. **导入语句优化**:
- 调整了部分模块的 `import` 语句顺序,使其符合 PEP 8 规范。
这些更改不涉及任何功能性变动,旨在提升代码库的整体质量、可维护性和开发体验。
This commit is contained in:
@@ -123,7 +123,7 @@ class RelationshipFetcher:
|
||||
# 获取用户特征点
|
||||
current_points = await person_info_manager.get_value(person_id, "points") or []
|
||||
forgotten_points = await person_info_manager.get_value(person_id, "forgotten_points") or []
|
||||
|
||||
|
||||
# 确保 points 是列表类型(可能从数据库返回字符串)
|
||||
if not isinstance(current_points, list):
|
||||
current_points = []
|
||||
@@ -195,25 +195,25 @@ class RelationshipFetcher:
|
||||
if relationships:
|
||||
# db_query 返回字典列表,使用字典访问方式
|
||||
rel_data = relationships[0]
|
||||
|
||||
|
||||
# 5.1 用户别名
|
||||
if rel_data.get("user_aliases"):
|
||||
aliases_list = [alias.strip() for alias in rel_data["user_aliases"].split(",") if alias.strip()]
|
||||
if aliases_list:
|
||||
aliases_str = "、".join(aliases_list)
|
||||
relation_parts.append(f"{person_name}的别名有:{aliases_str}")
|
||||
|
||||
|
||||
# 5.2 关系印象文本(主观认知)
|
||||
if rel_data.get("relationship_text"):
|
||||
relation_parts.append(f"你对{person_name}的整体认知:{rel_data['relationship_text']}")
|
||||
|
||||
|
||||
# 5.3 用户偏好关键词
|
||||
if rel_data.get("preference_keywords"):
|
||||
keywords_list = [kw.strip() for kw in rel_data["preference_keywords"].split(",") if kw.strip()]
|
||||
if keywords_list:
|
||||
keywords_str = "、".join(keywords_list)
|
||||
relation_parts.append(f"{person_name}的偏好和兴趣:{keywords_str}")
|
||||
|
||||
|
||||
# 5.4 关系亲密程度(好感分数)
|
||||
if rel_data.get("relationship_score") is not None:
|
||||
score_desc = self._get_relationship_score_description(rel_data["relationship_score"])
|
||||
|
||||
Reference in New Issue
Block a user