fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -107,7 +107,7 @@ class Neo4jManager:
|
||||
|
||||
self._connect()
|
||||
|
||||
def _connect(self):
|
||||
def _connect(self) -> None:
|
||||
"""建立 Neo4j 连接"""
|
||||
if not NEO4J_AVAILABLE:
|
||||
return
|
||||
@@ -121,7 +121,7 @@ class Neo4jManager:
|
||||
logger.error(f"Failed to connect to Neo4j: {e}")
|
||||
self._driver = None
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
"""关闭连接"""
|
||||
if self._driver:
|
||||
self._driver.close()
|
||||
@@ -137,7 +137,7 @@ class Neo4jManager:
|
||||
except BaseException:
|
||||
return False
|
||||
|
||||
def init_schema(self):
|
||||
def init_schema(self) -> None:
|
||||
"""初始化图数据库 Schema(约束和索引)"""
|
||||
if not self._driver:
|
||||
logger.error("Neo4j not connected")
|
||||
@@ -178,7 +178,7 @@ class Neo4jManager:
|
||||
|
||||
# ==================== 数据同步 ====================
|
||||
|
||||
def sync_project(self, project_id: str, project_name: str, project_description: str = ""):
|
||||
def sync_project(self, project_id: str, project_name: str, project_description: str = "") -> None:
|
||||
"""同步项目节点到 Neo4j"""
|
||||
if not self._driver:
|
||||
return
|
||||
@@ -196,7 +196,7 @@ class Neo4jManager:
|
||||
description=project_description,
|
||||
)
|
||||
|
||||
def sync_entity(self, entity: GraphEntity):
|
||||
def sync_entity(self, entity: GraphEntity) -> None:
|
||||
"""同步单个实体到 Neo4j"""
|
||||
if not self._driver:
|
||||
return
|
||||
@@ -225,7 +225,7 @@ class Neo4jManager:
|
||||
properties=json.dumps(entity.properties),
|
||||
)
|
||||
|
||||
def sync_entities_batch(self, entities: list[GraphEntity]):
|
||||
def sync_entities_batch(self, entities: list[GraphEntity]) -> None:
|
||||
"""批量同步实体到 Neo4j"""
|
||||
if not self._driver or not entities:
|
||||
return
|
||||
@@ -262,7 +262,7 @@ class Neo4jManager:
|
||||
entities=entities_data,
|
||||
)
|
||||
|
||||
def sync_relation(self, relation: GraphRelation):
|
||||
def sync_relation(self, relation: GraphRelation) -> None:
|
||||
"""同步单个关系到 Neo4j"""
|
||||
if not self._driver:
|
||||
return
|
||||
@@ -286,7 +286,7 @@ class Neo4jManager:
|
||||
properties=json.dumps(relation.properties),
|
||||
)
|
||||
|
||||
def sync_relations_batch(self, relations: list[GraphRelation]):
|
||||
def sync_relations_batch(self, relations: list[GraphRelation]) -> None:
|
||||
"""批量同步关系到 Neo4j"""
|
||||
if not self._driver or not relations:
|
||||
return
|
||||
@@ -318,7 +318,7 @@ class Neo4jManager:
|
||||
relations=relations_data,
|
||||
)
|
||||
|
||||
def delete_entity(self, entity_id: str):
|
||||
def delete_entity(self, entity_id: str) -> None:
|
||||
"""从 Neo4j 删除实体及其关系"""
|
||||
if not self._driver:
|
||||
return
|
||||
@@ -332,7 +332,7 @@ class Neo4jManager:
|
||||
id=entity_id,
|
||||
)
|
||||
|
||||
def delete_project(self, project_id: str):
|
||||
def delete_project(self, project_id: str) -> None:
|
||||
"""从 Neo4j 删除项目及其所有实体和关系"""
|
||||
if not self._driver:
|
||||
return
|
||||
@@ -949,7 +949,7 @@ def get_neo4j_manager() -> Neo4jManager:
|
||||
return _neo4j_manager
|
||||
|
||||
|
||||
def close_neo4j_manager():
|
||||
def close_neo4j_manager() -> None:
|
||||
"""关闭 Neo4j 连接"""
|
||||
global _neo4j_manager
|
||||
if _neo4j_manager:
|
||||
@@ -958,7 +958,7 @@ def close_neo4j_manager():
|
||||
|
||||
|
||||
# 便捷函数
|
||||
def sync_project_to_neo4j(project_id: str, project_name: str, entities: list[dict], relations: list[dict]):
|
||||
def sync_project_to_neo4j(project_id: str, project_name: str, entities: list[dict], relations: list[dict]) -> None:
|
||||
"""
|
||||
同步整个项目到 Neo4j
|
||||
|
||||
|
||||
Reference in New Issue
Block a user