chore: prune unused imports and duplicate import redefinitions

Remove unused imports (F401) and duplicate/shadowed import
redefinitions (F811) across the codebase using ruff's safe
autofixes. No behavioral changes -- imports only.

- ~1400 safe autofixes applied across 644 files (net -1072 lines)
- __init__.py re-exports preserved (excluded from F401 removal so
  public re-export surfaces stay intact)
- Re-exports that are imported or monkeypatched by tests but look
  unused in their defining module are kept with explicit # noqa:
  F401 (gateway/run.py load_dotenv; run_agent re-exports from
  agent.message_sanitization, agent.context_compressor,
  agent.retry_utils, agent.prompt_builder, agent.process_bootstrap,
  agent.codex_responses_adapter)
- Unsafe F841 (unused-variable) fixes deliberately skipped -- those
  can change behavior when the RHS has side effects
- ruff lints remain disabled in pyproject.toml (only PLW1514 is
  selected); this is a one-time cleanup, not a config change

Verification:
- python -m compileall: clean
- pytest --collect-only: all 27161 tests collect (zero import errors)
- core entry points import clean (run_agent, model_tools, cli,
  toolsets, hermes_state, batch_runner, gateway)
- static scan: every name any test imports directly from an edited
  module still resolves
This commit is contained in:
kshitijk4poor 2026-05-29 02:04:58 +05:30 committed by Teknium
parent a4d8f0f62a
commit 66827f8947
644 changed files with 254 additions and 1326 deletions

View file

@ -16,7 +16,6 @@ from __future__ import annotations
import json
from unittest.mock import MagicMock
import pytest
# ---------------------------------------------------------------------------

View file

@ -137,7 +137,6 @@ class TestGenerate:
assert result["error_type"] == "auth_required"
def test_b64_saves_to_cache(self, provider, tmp_path):
import base64
png_bytes = bytes.fromhex(_PNG_HEX)
fake_client = MagicMock()
fake_client.images.generate.return_value = _fake_response(b64=_b64_png())

View file

@ -4,7 +4,6 @@
from __future__ import annotations
import json
import os
from pathlib import Path
from unittest.mock import MagicMock, patch

View file

@ -1016,7 +1016,6 @@ class TestSessionSwitchBufferFlush:
old session to settle before clearing _prefetch_result, otherwise
the thread can race and re-populate the field after the clear."""
import threading
import time as _time
gate = threading.Event()
finished = threading.Event()

View file

@ -4,7 +4,6 @@ Salvaged from PRs #5301 (qaqcvc) and #5117 (vvvanguards).
"""
import json
import pytest
from plugins.memory.mem0 import Mem0MemoryProvider

View file

@ -6,7 +6,6 @@ without actually invoking those tools on the host.
from __future__ import annotations
import subprocess
from unittest.mock import MagicMock, patch
import pytest

View file

@ -12,7 +12,6 @@ import argparse
import asyncio
import json
from pathlib import Path
from unittest.mock import MagicMock, patch
import pytest

View file

@ -764,7 +764,6 @@ def test_cmd_install_refuses_windows(capsys):
def test_cmd_install_runs_pip_and_playwright(capsys):
"""End-to-end wiring: pip + playwright install invoked, returncodes handled."""
from plugins.google_meet.cli import _cmd_install
import subprocess as _sp
calls = []
class _FakeRes:

View file

@ -8,10 +8,7 @@ from __future__ import annotations
import base64
import json
import sys
import threading
import types
from pathlib import Path
from unittest.mock import patch
import pytest

View file

@ -835,8 +835,6 @@ def test_ws_events_swallows_cancellation_on_shutdown(tmp_path, monkeypatch):
the cancellation outcome deterministically.
"""
import asyncio
import types
import sys as _sys
home = tmp_path / ".hermes"
home.mkdir()

View file

@ -13,7 +13,7 @@ import secrets
import sys
import time
from pathlib import Path
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock
import pytest
from fastapi import FastAPI

View file

@ -5,13 +5,10 @@ RetainDBMemoryProvider lifecycle/tools/prefetch, thread management, connection p
"""
import json
import os
import sqlite3
import tempfile
import threading
import time
from pathlib import Path
from unittest.mock import MagicMock, patch, PropertyMock
from unittest.mock import MagicMock, patch
import pytest
@ -67,8 +64,6 @@ from plugins.memory.retaindb import (
_WriteQueue,
_build_overlay,
RetainDBMemoryProvider,
_ASYNC_SHUTDOWN,
_DEFAULT_BASE_URL,
)

View file

@ -16,9 +16,7 @@ Covers ``plugins/security-guidance/``:
* Bundled-plugin discovery via ``PluginManager.discover_and_load``.
"""
import importlib
import importlib.util
import json
import sys
import types
from pathlib import Path

View file

@ -5,7 +5,6 @@ from __future__ import annotations
import asyncio
from types import SimpleNamespace
from pathlib import Path
from unittest.mock import MagicMock
import pytest

View file

@ -20,9 +20,6 @@ from __future__ import annotations
import asyncio
import inspect
import os
import sys
from typing import Any, Dict, List
import pytest
@ -268,7 +265,7 @@ class TestRegistryResolution:
surfaces a precise "FOO_API_KEY is not set" error instead.
"""
_ensure_plugins_loaded()
from agent.web_search_registry import _resolve, get_provider
from agent.web_search_registry import _resolve
# No BRAVE_SEARCH_API_KEY (fixture cleared it).
result = _resolve("brave-free", capability="search")