fix: auto-fix code issues (cron)

- 修复隐式 Optional 类型注解 (RUF013)
- 修复不必要的赋值后返回 (RET504)
- 优化列表推导式 (PERF401)
- 修复未使用的参数 (ARG002)
- 清理重复导入
- 优化异常处理
This commit is contained in:
AutoFix Bot
2026-03-03 21:11:47 +08:00
parent d17a58ceae
commit 259f2c90d0
36 changed files with 1651 additions and 863 deletions

View File

@@ -304,7 +304,7 @@ class CollaborationManager:
)
self.db.conn.commit()
def revoke_share_link(self, share_id: str, revoked_by: str) -> bool:
def revoke_share_link(self, share_id: str, _revoked_by: str) -> bool:
"""撤销分享链接"""
if self.db:
cursor = self.db.conn.cursor()
@@ -335,26 +335,24 @@ class CollaborationManager:
(project_id,),
)
shares = []
for row in cursor.fetchall():
shares.append(
ProjectShare(
id=row[0],
project_id=row[1],
token=row[2],
permission=row[3],
created_by=row[4],
created_at=row[5],
expires_at=row[6],
max_uses=row[7],
use_count=row[8],
password_hash=row[9],
is_active=bool(row[10]),
allow_download=bool(row[11]),
allow_export=bool(row[12]),
),
return [
ProjectShare(
id=row[0],
project_id=row[1],
token=row[2],
permission=row[3],
created_by=row[4],
created_at=row[5],
expires_at=row[6],
max_uses=row[7],
use_count=row[8],
password_hash=row[9],
is_active=bool(row[10]),
allow_download=bool(row[11]),
allow_export=bool(row[12]),
)
return shares
for row in cursor.fetchall()
]
# ============ 评论和批注 ============
@@ -435,7 +433,10 @@ class CollaborationManager:
self.db.conn.commit()
def get_comments(
self, target_type: str, target_id: str, include_resolved: bool = True,
self,
target_type: str,
target_id: str,
include_resolved: bool = True,
) -> list[Comment]:
"""获取评论列表"""
if not self.db:
@@ -461,10 +462,7 @@ class CollaborationManager:
(target_type, target_id),
)
comments = []
for row in cursor.fetchall():
comments.append(self._row_to_comment(row))
return comments
return [self._row_to_comment(row) for row in cursor.fetchall()]
def _row_to_comment(self, row) -> Comment:
"""将数据库行转换为Comment对象"""
@@ -554,7 +552,10 @@ class CollaborationManager:
return cursor.rowcount > 0
def get_project_comments(
self, project_id: str, limit: int = 50, offset: int = 0,
self,
project_id: str,
limit: int = 50,
offset: int = 0,
) -> list[Comment]:
"""获取项目下的所有评论"""
if not self.db:
@@ -571,10 +572,7 @@ class CollaborationManager:
(project_id, limit, offset),
)
comments = []
for row in cursor.fetchall():
comments.append(self._row_to_comment(row))
return comments
return [self._row_to_comment(row) for row in cursor.fetchall()]
# ============ 变更历史 ============
@@ -697,10 +695,7 @@ class CollaborationManager:
(project_id, limit, offset),
)
records = []
for row in cursor.fetchall():
records.append(self._row_to_change_record(row))
return records
return [self._row_to_change_record(row) for row in cursor.fetchall()]
def _row_to_change_record(self, row) -> ChangeRecord:
"""将数据库行转换为ChangeRecord对象"""