From 7a7b191a6d2b0e64131ecd35b50c3a23fd0d38db Mon Sep 17 00:00:00 2001 From: Bu5hm4nn Date: Sun, 5 Apr 2026 08:43:07 +0200 Subject: [PATCH] fix: correct type annotations in databento_source.py - Fix return type of _load_from_cache and _df_to_daily_points to return list[DailyClosePoint] - Import DailyClosePoint from historical_provider - Use TYPE_CHECKING pattern for optional databento/pandas imports --- app/services/backtesting/databento_source.py | 27 ++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/services/backtesting/databento_source.py b/app/services/backtesting/databento_source.py index 3679296..fc85a8e 100644 --- a/app/services/backtesting/databento_source.py +++ b/app/services/backtesting/databento_source.py @@ -8,20 +8,31 @@ import logging from dataclasses import dataclass from datetime import date, timedelta from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any + +from app.services.backtesting.historical_provider import DailyClosePoint + +if TYPE_CHECKING: + import databento as db + import pandas as pd +else: + db = None + pd = None + +DATABENTO_AVAILABLE = False logger = logging.getLogger(__name__) # Try to import databento, gracefully degrade if not available try: - import databento as db - import pandas as pd + import databento as _db + import pandas as _pd + db = _db + pd = _pd DATABENTO_AVAILABLE = True except ImportError: - db = None - pd = None - DATABENTO_AVAILABLE = False + pass @dataclass @@ -98,7 +109,7 @@ class DatabentoHistoricalPriceSource: self._client = db.Historical(key=self.config.api_key) return self._client - def _load_from_cache(self, key: DatabentoCacheKey) -> list[dict[str, Any]] | None: + def _load_from_cache(self, key: DatabentoCacheKey) -> list[DailyClosePoint] | None: """Load cached data if available and fresh.""" cache_file = key.cache_path(self.config.cache_dir) meta_file = key.metadata_path(self.config.cache_dir) @@ -166,7 +177,7 @@ class DatabentoHistoricalPriceSource: ) return data.to_df() - def _df_to_daily_points(self, df: Any) -> list[Any]: + def _df_to_daily_points(self, df: Any) -> list[DailyClosePoint]: """Convert DataFrame to DailyClosePoint list with OHLC data.""" from app.services.backtesting.historical_provider import DailyClosePoint