Skip to content

chore(lint): remove unused imports + variables (ruff F401/F841) - #210

Merged
debpalash merged 1 commit into
mainfrom
chore/lint-autofix
Jun 1, 2026
Merged

chore(lint): remove unused imports + variables (ruff F401/F841)#210
debpalash merged 1 commit into
mainfrom
chore/lint-autofix

Conversation

@debpalash

@debpalash debpalash commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Autofixes the dead code behind the CodeQL py/unused-import and py/unused-local-variable note-level alerts — actually removing it rather than dismissing it (these aren't false positives; the code really did have unused imports/vars).

  • 68 safe fixes via ruff check --select F401,F841 --fix across 29 backend files — dead stdlib/symbol imports (io, sys, json, torch, typing.Optional, fastapi.HTTPException, …) and unused locals.
  • Only ruff's safe fixes applied. The 9 "unsafe" fixes and the audio_dsp.py numpy availability-probe import were left untouched (no --unsafe-fixes).
  • Reviewed the removal list first: all dead symbol/stdlib imports — no registration/side-effect imports.

Not touched (deliberately):

  • py/empty-except (109) — needs per-site judgement (what to log/re-raise), not safely autofixable.
  • frontend js/unused-local-variable — eslint's no-unused-vars has no autofix.
  • the loopback-low-risk path-injection/log-injection/stack-trace-exposure alerts — real patterns, left visible (dismissing would hide future regressions).

Verified: full tests/ suite unchanged at 601 passed — the import removals broke nothing. (The 2 test_supertonic3 failures are pre-existing on main: local .venv engine/license state, green in CI.)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Optimized internal code by removing unused imports and dependencies across backend services and API modules.
    • Cleaned up exception handling for improved code consistency.
    • No user-facing functionality or API behavior was changed.

Autofixes the genuine lint behind the CodeQL py/unused-import and
py/unused-local-variable note-level alerts — actually removing the dead
code rather than dismissing it. 68 safe fixes via 'ruff check --select
F401,F841 --fix' across 29 backend files (dead stdlib/symbol imports like
io/sys/json/torch/typing.Optional and unused locals). Only ruff's safe
fixes applied — the 9 'unsafe' fixes and the audio_dsp numpy availability
import were left untouched.

Not touched: empty-except (needs per-site judgement, not autofixable);
frontend js/unused-local-variable (eslint no-unused-vars has no autofix);
the loopback-low-risk path/log/stack-trace alerts (real, left visible).

Verified: full tests/ suite unchanged at 601 passed (the 2 test_supertonic3
failures are pre-existing on main, local .venv state, green in CI).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 21131b7a-5ce4-4b0d-8026-72e090a92b00

📥 Commits

Reviewing files that changed from the base of the PR and between 2531223 and 005746a.

📒 Files selected for processing (29)
  • backend/api/routers/batch.py
  • backend/api/routers/capture.py
  • backend/api/routers/capture_ws.py
  • backend/api/routers/dub_core.py
  • backend/api/routers/dub_export.py
  • backend/api/routers/dub_generate.py
  • backend/api/routers/gallery.py
  • backend/api/routers/generation.py
  • backend/api/routers/marketplace.py
  • backend/api/routers/openai_compat.py
  • backend/api/routers/settings.py
  • backend/api/routers/setup/models.py
  • backend/api/routers/system.py
  • backend/api/routers/tools.py
  • backend/api/routers/tts_stream.py
  • backend/main.py
  • backend/services/asr_backend.py
  • backend/services/dub_pipeline.py
  • backend/services/ffmpeg_utils.py
  • backend/services/gpu_sandbox.py
  • backend/services/model_manager.py
  • backend/services/segmentation.py
  • backend/services/speaker_clone.py
  • backend/services/translator.py
  • backend/services/tts_backend.py
  • backend/services/video_context.py
  • backend/services/watermark.py
  • backend/tests/test_capture_ws.py
  • backend/tests/test_tts_backend_lifecycle.py
💤 Files with no reviewable changes (16)
  • backend/services/watermark.py
  • backend/api/routers/generation.py
  • backend/api/routers/settings.py
  • backend/services/video_context.py
  • backend/api/routers/dub_generate.py
  • backend/services/speaker_clone.py
  • backend/services/tts_backend.py
  • backend/tests/test_capture_ws.py
  • backend/api/routers/tts_stream.py
  • backend/services/model_manager.py
  • backend/tests/test_tts_backend_lifecycle.py
  • backend/api/routers/batch.py
  • backend/services/gpu_sandbox.py
  • backend/api/routers/dub_export.py
  • backend/main.py
  • backend/api/routers/capture_ws.py

📝 Walkthrough

Walkthrough

This pull request removes unused imports across the backend codebase in a systematic cleanup pass. API routers shed fastapi/stdlib imports no longer used, services eliminate typing/stdlib dependencies, and test files remove unused imports. Module bootstrap reorders torch/torchaudio imports to reduce overhead, and exception handlers are simplified by removing unused bindings.

Changes

Import cleanup across routers, services, and tests

Layer / File(s) Summary
Router module imports
backend/api/routers/batch.py, capture.py, capture_ws.py, dub_core.py, dub_generate.py, dub_export.py, gallery.py, generation.py, marketplace.py, openai_compat.py, settings.py, setup/models.py, system.py, tools.py, tts_stream.py
API routers remove unused FastAPI response types (StreamingResponse, FileResponse, JSONResponse), stdlib utilities (io, json, time, subprocess), and service imports (Query, Response, Depends, HTTPException, active_backend_id, DIARIZATION_ERR_LOAD). generation.py moves audio DSP imports to lazy-load inside _run_inference.
Service imports and bootstrap
backend/main.py, services/asr_backend.py, dub_pipeline.py, ffmpeg_utils.py, gpu_sandbox.py, model_manager.py, segmentation.py, speaker_clone.py, translator.py, tts_backend.py, video_context.py, watermark.py
Services remove unused typing imports (Optional, Any), dataclass utilities (asdict), and stdlib modules (json, time). Main module reorders torchaudio import before audio backend config. ASR and FFmpeg exception handlers simplified by removing unused exception bindings. GPU worker subprocess removes standalone torch import. Watermark updates torch import while dropping struct and numpy.
Test file cleanup
backend/tests/test_capture_ws.py, test_tts_backend_lifecycle.py
Test modules remove unused imports (pytest, pathlib.Path) from import lists while preserving all test logic and assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing unused imports and variables via ruff linting fixes F401/F841.
Description check ✅ Passed The PR description is comprehensive, covering the summary, specific changes (68 safe fixes across 29 files), type (chore/lint), testing verification (601 tests passed), and what was deliberately excluded.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/lint-autofix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR applies ruff --select F401,F841 --fix (safe-only) across 29 backend files to remove unused imports and local variables that were flagged by CodeQL py/unused-import and py/unused-local-variable alerts. All 68 removals are genuinely dead symbols with no side effects; the test suite is reported to be unchanged at 601 passed.

  • Unused stdlib/third-party imports removed (io, sys, json, time, uuid, torch, soundfile, numpy, torchaudio, typing.Optional, typing.Any, typing.List, dataclasses.asdict, fastapi.responses.*, fastapi.Depends, fastapi.Query, etc.) across all 29 backend files.
  • Unused local exception variables (except IndexError as e, except Exception as e) collapsed to bare-exception forms in asr_backend.py and ffmpeg_utils.py.
  • Unused function-scoped imports (soundfile/numpy inside _transcribe_buffer, torch inside _generate/_run_tts, re/traceback inside _transcribe) removed since the functions use higher-level wrappers that already encapsulate those dependencies.

Confidence Score: 5/5

Safe to merge — every removed symbol is genuinely dead and no registration or side-effect import was touched.

All 68 removals are straightforward dead-code cleanups: unused stdlib names, third-party symbols imported but never referenced, and bare exception variable bindings where the variable was never read. The most attention-worthy cases were each verified by reading the post-removal function bodies — none reference the removed names.

No files require special attention; the removals in dub_core.py and main.py were spot-checked and confirmed clean.

Important Files Changed

Filename Overview
backend/api/routers/dub_core.py Removed 10+ unused imports; DIARIZATION_ERR_LOAD only appears in a comment, not in code — removal is safe.
backend/main.py Removed top-level soundfile as sf and torch which were not referenced anywhere in main.py.
backend/api/routers/capture_ws.py Removed io at module level and soundfile/numpy from inside _transcribe_buffer; function delegates to higher-level wrappers.
backend/services/watermark.py Removed struct and numpy as np; confirmed no direct np.* or struct.* calls — all numeric ops use torch.
backend/services/gpu_sandbox.py Removed json, time, and torch from _worker; torch ops flow through model/dsp wrappers, torchaudio still present.
backend/services/asr_backend.py Removed typing.Optional and collapsed except IndexError as e; exception variable was never referenced.
backend/services/ffmpeg_utils.py Collapsed except Exception as e: raise to except Exception: raise; variable unused since body immediately re-raises.
backend/api/routers/generation.py Removed top-level apply_mastering/normalize_audio; both still imported lazily inside _generate closure at runtime.
backend/api/routers/system.py Removed LogsResponse, FlushMemoryResponse and model as _current_model; _current_model never referenced in flush_memory.
backend/tests/test_capture_ws.py Removed unused import pytest; file only uses os and sys for path manipulation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ruff check --select F401,F841 --fix] --> B{68 safe fixes across 29 files}
    B --> C[Unused module-level imports]
    B --> D[Unused function-scoped imports]
    B --> E[Unused exception variables]
    C --> C1[stdlib: io, sys, json, time, uuid, struct]
    C --> C2[typing: Optional, Any, List]
    C --> C3[3rd-party: torch, soundfile, numpy, torchaudio]
    C --> C4[fastapi responses and helpers]
    C --> C5[internal symbols]
    D --> D1[soundfile+numpy in capture_ws._transcribe_buffer]
    D --> D2[torch in openai_compat._run_tts]
    D --> D3[torch in tts_stream._generate]
    D --> D4[torch in gpu_sandbox._worker]
    D --> D5[re+traceback in dub_core._transcribe]
    E --> E1[except IndexError as e in asr_backend.py]
    E --> E2[except Exception as e: raise in ffmpeg_utils.py]
Loading

Reviews (1): Last reviewed commit: "chore(lint): remove unused imports + var..." | Re-trigger Greptile

@debpalash
debpalash merged commit 4772905 into main Jun 1, 2026
15 checks passed
@debpalash
debpalash deleted the chore/lint-autofix branch June 1, 2026 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant