fix(review): address PR review findings for CORE-003

Critical fixes:
- Add math.isfinite() check to reject NaN/Infinity in _safe_quote_price
- Raise TypeError instead of silent 0.0 fallback in price_feed.py
- Use dict instead of Mapping for external data validation

Type improvements:
- Add PortfolioSnapshot TypedDict for type safety
- Add DisplayMode and EntryBasisMode Literal types
- Add explicit dict[str, Any] annotation in to_dict()
- Remove cast() in favor of type comment validation
This commit is contained in:
Bu5hm4nn
2026-03-30 00:39:02 +02:00
parent 1dce5bfd23
commit 98e3208b5e
4 changed files with 48 additions and 19 deletions

View File

@@ -2,7 +2,6 @@ from __future__ import annotations
from collections.abc import Iterable, Mapping
from datetime import date, datetime
from typing import cast
from app.core.pricing.black_scholes import (
DEFAULT_RISK_FREE_RATE,
@@ -153,7 +152,7 @@ def option_row_greeks(
implied_volatility = float(iv_raw) if isinstance(iv_raw, (int, float)) else 0.0
volatility = implied_volatility if implied_volatility > 0 else DEFAULT_VOLATILITY
option_type_typed: OptionType = cast(OptionType, option_type)
# option_type is validated to be in {"call", "put"} above, so it's safe to pass
try:
pricing = black_scholes_price_and_greeks(
BlackScholesInputs(
@@ -162,7 +161,7 @@ def option_row_greeks(
time_to_expiry=days_to_expiry / 365.0,
risk_free_rate=risk_free_rate,
volatility=volatility,
option_type=option_type_typed,
option_type=option_type, # type: ignore[arg-type]
valuation_date=valuation,
)
)