chore(lint): remove unused imports + variables (ruff F401/F841) - #210
Conversation
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (29)
💤 Files with no reviewable changes (16)
📝 WalkthroughWalkthroughThis 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. ChangesImport cleanup across routers, services, and tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
| 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]
Reviews (1): Last reviewed commit: "chore(lint): remove unused imports + var..." | Re-trigger Greptile
Autofixes the dead code behind the CodeQL
py/unused-importandpy/unused-local-variablenote-level alerts — actually removing it rather than dismissing it (these aren't false positives; the code really did have unused imports/vars).ruff check --select F401,F841 --fixacross 29 backend files — dead stdlib/symbol imports (io,sys,json,torch,typing.Optional,fastapi.HTTPException, …) and unused locals.audio_dsp.pynumpyavailability-probe import were left untouched (no--unsafe-fixes).Not touched (deliberately):
py/empty-except(109) — needs per-site judgement (what to log/re-raise), not safely autofixable.js/unused-local-variable— eslint'sno-unused-varshas no autofix.path-injection/log-injection/stack-trace-exposurealerts — real patterns, left visible (dismissing would hide future regressions).Verified: full
tests/suite unchanged at 601 passed — the import removals broke nothing. (The 2test_supertonic3failures are pre-existing onmain: local.venvengine/license state, green in CI.)🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes