From ff833ce7e07fd7aa9a771664e35307078d27aada Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 10 Sep 2026 17:39:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B8=85=E7=90=8622=E4=B8=AAF841=20unus?= =?UTF-8?q?ed-variable=EF=BC=8C=E8=A7=A3=E9=99=A4CI=20Validate-Style?= =?UTF-8?q?=E9=98=BB=E5=A1=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 全部为 except Exception as e: 中变量e未使用的模式, ruff自动修复将 e: 改为 :。不涉及任何业务逻辑变更。 --- apps/api/app/api/routes/asset_diagnosis.py | 2 +- apps/api/app/api/routes/chunked_upload.py | 2 +- .../api/routes/generation_variant_plans.py | 4 ++-- .../routes/templates_editor/ai_features.py | 4 ++-- .../app/api/routes/templates_editor/clips.py | 22 +++++++++---------- apps/api/app/api/routes/voice_clones.py | 4 ++-- apps/api/app/api/routes/voices.py | 6 ++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apps/api/app/api/routes/asset_diagnosis.py b/apps/api/app/api/routes/asset_diagnosis.py index 9ed30be22..25b879869 100644 --- a/apps/api/app/api/routes/asset_diagnosis.py +++ b/apps/api/app/api/routes/asset_diagnosis.py @@ -336,7 +336,7 @@ def get_project_asset_diagnosis( assets.extend(asset_repository.list_by_library(library.id)) except HTTPException: raise - except Exception as e: + except Exception: logger.exception("素材诊断查询失败: project_id=%s", project_id) # 返回空诊断结果,避免 500 return _build_diagnosis(project_id, []) diff --git a/apps/api/app/api/routes/chunked_upload.py b/apps/api/app/api/routes/chunked_upload.py index f99adc0db..8407c842d 100644 --- a/apps/api/app/api/routes/chunked_upload.py +++ b/apps/api/app/api/routes/chunked_upload.py @@ -177,7 +177,7 @@ def _cleanup_expired_uploads() -> int: meta_file.unlink() cleaned += 1 logger.info(f"Cleaned up expired upload: {upload_id}") - except Exception as e: + except Exception: logger.exception("Failed to cleanup upload metadata: %s", meta_file) return cleaned diff --git a/apps/api/app/api/routes/generation_variant_plans.py b/apps/api/app/api/routes/generation_variant_plans.py index 7b603976d..7c1de1123 100644 --- a/apps/api/app/api/routes/generation_variant_plans.py +++ b/apps/api/app/api/routes/generation_variant_plans.py @@ -107,7 +107,7 @@ def create_variant_plans( ) if _latest: source_plan_id = _latest.id - except Exception as e: + except Exception: logger.exception("[variant-plans] 源 plan 解析失败") if not source_plan_id: @@ -121,7 +121,7 @@ def create_variant_plans( from app.api.routes.generation_tasks import _query_voice_durations voice_durations = _query_voice_durations(db, voices) - except Exception as e: + except Exception: logger.exception("[variant-plans] 配音时长查询失败(按占位段长选片)") voice_durations = [0.0] * request.count diff --git a/apps/api/app/api/routes/templates_editor/ai_features.py b/apps/api/app/api/routes/templates_editor/ai_features.py index 0f4a358b1..97efef393 100755 --- a/apps/api/app/api/routes/templates_editor/ai_features.py +++ b/apps/api/app/api/routes/templates_editor/ai_features.py @@ -65,7 +65,7 @@ def _build_asset_analyses( if url: video_urls.append(url) valid_asset_ids.append(aid) - except Exception as e: + except Exception: logger.exception("获取素材URL失败: asset_id=%s", aid) if not video_urls: @@ -176,7 +176,7 @@ def editor_ai_recommend( ) try: db.rollback() - except Exception as e: + except Exception: logger.exception("db rollback failed in ai_recommend") raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, diff --git a/apps/api/app/api/routes/templates_editor/clips.py b/apps/api/app/api/routes/templates_editor/clips.py index 0ba685c8f..fb774321d 100755 --- a/apps/api/app/api/routes/templates_editor/clips.py +++ b/apps/api/app/api/routes/templates_editor/clips.py @@ -140,7 +140,7 @@ def _build_asset_url_map( try: assets = asset_repo.find_by_ids(unique_ids) asset_map = {a.id: a for a in assets} - except Exception as e: + except Exception: logger.exception("批量查询素材失败: asset_ids=%s", asset_ids) return {aid: None for aid in asset_ids if aid} @@ -155,7 +155,7 @@ def _build_asset_url_map( result[aid] = None continue result[aid] = storage.get_download_url(storage_key, expires_seconds=3600) - except Exception as e: + except Exception: logger.exception("生成素材签名URL失败: asset_id=%s", aid) result[aid] = None @@ -486,7 +486,7 @@ def _get_mediakit_recommendations( if url: video_urls.append(url) valid_asset_ids.append(asset_id) - except Exception as e: + except Exception: logger.exception("获取素材URL失败: asset_id=%s", asset_id) if not video_urls: @@ -987,7 +987,7 @@ def _update_mediakit_recommendations_async( # pragma: no cover if storage_key and mime.startswith("video/"): try: video_url = storage.get_download_url(storage_key) - except Exception as e: + except Exception: logger.exception("后台任务: 获取素材URL失败: asset_id=%s", asset_id) # 构建该素材的占用区间列表(排除已更新片段) @@ -1039,7 +1039,7 @@ def _update_mediakit_recommendations_async( # pragma: no cover asset_id, len(scene_changes), ) - except Exception as cache_err: + except Exception: # 缓存写入失败不影响本次片段更新 logger.exception( "后台任务: 场景点缓存写入失败: asset_id=%s", @@ -1123,7 +1123,7 @@ def _update_mediakit_recommendations_async( # pragma: no cover recommended_start + clip_duration, plan_id, ) - except Exception as me: + except Exception: logger.exception( "后台任务: 同步素材区间记录失败,回滚本次片段更新: clip_id=%s", clip.id, @@ -1142,27 +1142,27 @@ def _update_mediakit_recommendations_async( # pragma: no cover asset_id, recommended_start, ) - except Exception as ue: + except Exception: logger.exception("后台任务: 单个片段更新失败: clip_id=%s", clip.id) try: db.rollback() - except Exception as e: + except Exception: pass continue logger.info("后台任务完成: plan_id=%s 成功更新 %d 个片段", plan_id, updated_count) - except Exception as e: + except Exception: # 后台任务失败不影响已创建的片段,静默处理 logger.exception("后台任务异常: plan_id=%s", plan_id) if db: try: db.rollback() - except Exception as e: + except Exception: pass finally: if db: try: db.close() - except Exception as e: + except Exception: pass diff --git a/apps/api/app/api/routes/voice_clones.py b/apps/api/app/api/routes/voice_clones.py index 5c08b9649..940e156dd 100755 --- a/apps/api/app/api/routes/voice_clones.py +++ b/apps/api/app/api/routes/voice_clones.py @@ -167,7 +167,7 @@ def create_voice_clone( # P2-3: Celery 调度失败时标记 profile 为 failed,避免永久卡在 processing try: workflow.process_clone_failure(profile.id, f"Celery 任务调度失败: {e}") - except Exception as inner_e: + except Exception: logger.exception("Failed to mark profile as failed after dispatch error") return _to_response(profile) @@ -281,7 +281,7 @@ def retry_voice_clone( # P2-3: Celery 调度失败时标记 profile 为 failed,避免永久卡在 processing try: workflow.process_clone_failure(profile.id, f"Celery 任务调度失败: {e}") - except Exception as inner_e: + except Exception: logger.exception("Failed to mark profile as failed after dispatch error") return _to_response(profile) diff --git a/apps/api/app/api/routes/voices.py b/apps/api/app/api/routes/voices.py index 4ef595277..8da45e69a 100755 --- a/apps/api/app/api/routes/voices.py +++ b/apps/api/app/api/routes/voices.py @@ -105,7 +105,7 @@ def _resolve_preset_preview_url( _preset_preview_cache[voice_id] = (audio_url, time.time()) logger.info("Preset voice preview generated: %s", voice_id) return audio_url - except Exception as e: + except Exception: logger.exception("Failed to generate preset voice preview: voice_id=%s", voice_id) return fallback_url @@ -126,7 +126,7 @@ def _resolve_all_preset_preview_urls( for p in presets: try: result_map[p.voice_id] = _resolve_preset_preview_url(p.voice_id, p.preview_url, cosyvoice) - except Exception as e: + except Exception: logger.exception("Failed to resolve preset preview URL: voice_id=%s", p.voice_id) result_map[p.voice_id] = p.preview_url return result_map @@ -732,7 +732,7 @@ def _find_or_create_voice_library_for_extract(*, user_id, project_repository, as if session is not None: try: session.rollback() - except Exception as e: + except Exception: logger.exception("session rollback failed in _find_or_create_voice_library") for lib in asset_library_repository.find_by_project(project.id): kind = lib.kind.value if hasattr(lib.kind, "value") else lib.kind -- 2.54.0