Skip to content

Commit fffcc17

Browse files
author
BESS Solutions
committed
fix: resolve ruff UP045/UP037/I001/F401 and mypy attr-defined in CMgPredictor
- Replace Optional[X] with X | None (UP045) - Remove quoted type annotations (UP037) - Sort imports and remove unused AsyncMock in test files (I001, F401) - Change _run_session session param: object to Any (mypy fix) - Remove unused Optional import (F401)
1 parent 6a5b3ca commit fffcc17

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

src/interfaces/cmg_predictor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import time as _time
3333
from dataclasses import dataclass, field
3434
from pathlib import Path
35-
from typing import Optional
35+
from typing import Any
3636

3737
import structlog
3838

@@ -154,8 +154,8 @@ def __init__(
154154
self,
155155
node: str = "Maitencillo",
156156
model_path: str | Path = "models/price_predictor.onnx",
157-
model_p10_path: Optional[str | Path] = None,
158-
model_p90_path: Optional[str | Path] = None,
157+
model_p10_path: str | Path | None = None,
158+
model_p90_path: str | Path | None = None,
159159
history_window: int = 192, # 8 days → supports lag_168h
160160
alpha: float = 0.3,
161161
cache_ttl_s: float = _CACHE_TTL_S,
@@ -173,7 +173,7 @@ def __init__(
173173
log.info("cmg_predictor.using_int8", node=node, path=str(int8_path))
174174

175175
# Quantile model paths (auto-discover from base path)
176-
def _q_path(suffix: str, override: Optional[str | Path]) -> Path:
176+
def _q_path(suffix: str, override: str | Path | None) -> Path:
177177
if override:
178178
return Path(override)
179179
base = Path(model_path)
@@ -198,7 +198,7 @@ def _q_path(suffix: str, override: Optional[str | Path]) -> Path:
198198
self._smooth: dict[int, float] = {h: _HOURLY_MEAN_CMG[h] for h in range(24)}
199199

200200
# Forecast cache: (timestamp_s, [PriceForecast])
201-
self._cache: Optional[tuple[float, list[PriceForecast]]] = None
201+
self._cache: tuple[float, list[PriceForecast]] | None = None
202202

203203
# ── Model Loading ─────────────────────────────────────────────────────────
204204

@@ -302,7 +302,7 @@ def load_history_from_csv(self, csv_path: Path) -> int:
302302
def predict_next_24h(
303303
self,
304304
current_hour: int,
305-
current_cmg: Optional[float] = None,
305+
current_cmg: float | None = None,
306306
) -> list[PriceForecast]:
307307
"""Generate 24h price forecasts with uncertainty bands.
308308
@@ -380,7 +380,7 @@ def _make_feature_vector(
380380
lag_168h: float,
381381
day_of_week: float = 0.0,
382382
soc_pct: float = 50.0,
383-
) -> "np.ndarray":
383+
) -> np.ndarray:
384384
"""Build the input feature vector for ONNX inference."""
385385
is_weekend = float(int(day_of_week) >= 5)
386386
if self._n_features == 11:
@@ -401,7 +401,7 @@ def _make_feature_vector(
401401
]
402402
return np.array([vec], dtype=np.float32)
403403

404-
def _run_session(self, session: object, features: "np.ndarray") -> float:
404+
def _run_session(self, session: Any, features: np.ndarray) -> float:
405405
"""Run a single ONNX session and return scalar output."""
406406
out = session.run(None, {self._input_name: features}) # type: ignore[union-attr]
407407
return float(out[0].flatten()[0])

tests/test_dashboard_api_handlers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
from __future__ import annotations
1313

1414
import json
15-
from unittest.mock import AsyncMock, MagicMock
15+
from unittest.mock import MagicMock
1616

1717
import pytest
18-
1918
from src.interfaces.dashboard_api import DashboardAPI, DashboardState
2019

21-
2220
# ---------------------------------------------------------------------------
2321
# Helpers
2422
# ---------------------------------------------------------------------------

tests/test_luna2000_driver_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
from __future__ import annotations
99

10-
from unittest.mock import AsyncMock, MagicMock, patch
10+
from unittest.mock import MagicMock, patch
1111

1212
import pytest
13-
1413
from src.drivers.luna2000_driver import BatteryMode, LUNADriver, LUNATelemetry
1514

1615
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)