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
- Open
router/main.py.
- Move the imports (
json, datetime, asyncpg, sqlite3, etc.) to the top of the file.
- 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)
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
router/main.py.json,datetime,asyncpg,sqlite3, etc.) to the top of the file.Code Example / Diff