refactor: address python review findings

- Move FRED credential registration to FastAPI lifespan (was fragile
  import-order-dependent side-effect)
- Add noqa E402 annotations for imports after curl_cffi patch
- Fix all return type hints: bare dict -> dict[str, Any]
- Move yfinance import to module level (was inline in functions)
- Fix datetime.now() -> datetime.now(tz=timezone.utc) in openbb_service
- Add try/except error handling to Group B service functions
- Fix dict mutation in relative_rotation (immutable pattern)
- Extract _classify_rrg_quadrant helper function
- Fix type builtin shadow in routes_economy (type -> gdp_type)
- Fix falsy int guard (if year: -> if year is not None:)
- Remove user input echo from error messages
This commit is contained in:
Yaojia Wang
2026-03-19 17:40:47 +01:00
parent e2cf6e2488
commit 89bdc6c552
6 changed files with 118 additions and 80 deletions

View File

@@ -23,10 +23,10 @@ async def macro_cpi(country: str = Query(default="united_states", max_length=50,
@router.get("/macro/gdp", response_model=ApiResponse)
@safe
async def macro_gdp(
type: str = Query(default="real", pattern="^(nominal|real|forecast)$"),
gdp_type: str = Query(default="real", pattern="^(nominal|real|forecast)$"),
):
"""GDP: nominal, real, or forecast."""
data = await economy_service.get_gdp(gdp_type=type)
data = await economy_service.get_gdp(gdp_type=gdp_type)
return ApiResponse(data=data)