Skip to content

[LHF-02] Code Clutter via Scattered Redundant Inline Imports #42

Description

@sheepdestroyer

Location

router/main.py (Inside _save_free_models_roster, _save_best_model_to_disk, _purge_stale_deployments, get_goose_sessions, etc.)

Problem Description

Functions repeatedly re-import core modules (json, datetime, sqlite3, asyncpg, etc.) using alternative internal aliases (e.g., import json as _json, import datetime as _dt). This adds readability friction and violates PEP 8 top-level naming conventions.

Fix Overview

Clean out all inner module declarations and relocate essential packages cleanly to the top-level import statement field.

Proposed Implementation Steps

  1. Open router/main.py.
  2. Move the imports (json, datetime, asyncpg, sqlite3, etc.) to the top of the file.
  3. Remove the inline imports inside the functions and update the variables to use the standard global package names.

Code Example / Diff

@@ -1189,5 +1189,3 @@
 def _save_free_models_roster(free_models: list[dict]) -> None:
-    import json as _json
-    import datetime as _dt
     payload = {
         "models": free_models,
-        "updated_at": _dt.datetime.utcnow().isoformat() + "Z",
+        "updated_at": datetime.utcnow().isoformat() + "Z",
         "count": len(free_models)
     }
     try:
         with open("/config/router_dir/free_models_roster.json", "w") as f:
-            _json.dump(payload, f, indent=2)
+            json.dump(payload, f, indent=2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestjulesIssues for Jules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions