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:
Bu5hm4nn
2026-03-30 00:05:09 +02:00
parent 36ba8731e6
commit 887565be74
15 changed files with 193 additions and 55 deletions

View File

@@ -125,7 +125,11 @@ def _require_non_empty_string(data: dict[str, Any], field_name: str) -> str:
def _decimal_text(value: Decimal) -> str:
if value == value.to_integral():
return str(value.quantize(Decimal("1")))
return format(value.normalize(), "f") if value.normalize().as_tuple().exponent < 0 else str(value)
normalized = value.normalize()
exponent = normalized.as_tuple().exponent
if isinstance(exponent, int) and exponent < 0:
return format(normalized, "f")
return str(normalized)
def _parse_decimal_payload(

View File

@@ -548,29 +548,6 @@ class PortfolioRepository:
and payload.get("email_alerts") is False
)
@classmethod
def _serialize_value(cls, key: str, value: Any) -> Any:
if key in cls._MONEY_FIELDS:
return {"value": cls._decimal_to_string(value), "currency": cls.PERSISTENCE_CURRENCY}
if key in cls._WEIGHT_FIELDS:
return {"value": cls._decimal_to_string(value), "unit": cls.PERSISTENCE_WEIGHT_UNIT}
if key in cls._PRICE_PER_WEIGHT_FIELDS:
return {
"value": cls._decimal_to_string(value),
"currency": cls.PERSISTENCE_CURRENCY,
"per_weight_unit": cls.PERSISTENCE_WEIGHT_UNIT,
}
if key in cls._RATIO_FIELDS:
return {"value": cls._decimal_to_string(value), "unit": "ratio"}
if key in cls._PERCENT_FIELDS:
return {"value": cls._decimal_to_string(value), "unit": "percent"}
if key in cls._INTEGER_FIELDS:
return cls._serialize_integer(value, unit="seconds")
if key == "positions" and isinstance(value, list):
# Already serialized as dicts from _to_persistence_payload
return value
return value
@classmethod
def _deserialize_value(cls, key: str, value: Any) -> Any:
if key in cls._MONEY_FIELDS: