fix(types): resolve all mypy type errors (CORE-003)
- Fix return type annotation for get_default_premium_for_product - Add type narrowing for Weight|Money union using _as_money helper - Add isinstance checks before float() calls for object types - Add type guard for Decimal.exponent comparison - Use _unit_typed and _currency_typed properties for type narrowing - Cast option_type to OptionType Literal after validation - Fix provider type hierarchy in backtesting services - Add types-requests to dev dependencies - Remove '|| true' from CI type-check job All 36 mypy errors resolved across 15 files.
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from datetime import date, timedelta
|
||||
from math import isfinite
|
||||
from typing import Protocol
|
||||
from typing import Protocol, cast
|
||||
|
||||
from app.models.backtest import ProviderRef
|
||||
|
||||
@@ -12,7 +12,7 @@ try:
|
||||
except ImportError: # pragma: no cover - optional in tests
|
||||
yf = None
|
||||
|
||||
from app.core.pricing.black_scholes import BlackScholesInputs, black_scholes_price_and_greeks
|
||||
from app.core.pricing.black_scholes import BlackScholesInputs, OptionType, black_scholes_price_and_greeks
|
||||
from app.models.strategy_template import TemplateLeg
|
||||
|
||||
|
||||
@@ -186,7 +186,10 @@ class YFinanceHistoricalPriceSource:
|
||||
return None
|
||||
if not hasattr(row_date, "date"):
|
||||
raise TypeError(f"historical row date must support .date(), got {type(row_date)!r}")
|
||||
normalized_close = float(close)
|
||||
if isinstance(close, (int, float)):
|
||||
normalized_close = float(close)
|
||||
else:
|
||||
raise TypeError(f"close must be numeric, got {type(close)!r}")
|
||||
if not isfinite(normalized_close):
|
||||
raise ValueError("historical close must be finite")
|
||||
return DailyClosePoint(date=row_date.date(), close=normalized_close)
|
||||
@@ -355,7 +358,7 @@ class SyntheticHistoricalProvider:
|
||||
time_to_expiry=remaining_days / 365.0,
|
||||
risk_free_rate=self.risk_free_rate,
|
||||
volatility=self.implied_volatility,
|
||||
option_type=option_type,
|
||||
option_type=cast(OptionType, option_type),
|
||||
valuation_date=valuation_date,
|
||||
)
|
||||
).price
|
||||
|
||||
Reference in New Issue
Block a user