You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def_parse_market(raw: Any) ->UnifiedMarket:
"""Best-effort parse of a raw market dict into UnifiedMarket."""ifisinstance(raw, UnifiedMarket):
returnrawifisinstance(raw, dict):
return_convert_market(raw)
returnraw# ← returns Any here, annotation says UnifiedMarket
The else branch returns raw unchanged, which is typed Any. The declared return type -> UnifiedMarket is false: callers believe they receive a UnifiedMarket but may receive anything at runtime.
Line 37 — _parse_event
def_parse_event(raw: Any) ->UnifiedEvent:
"""Best-effort parse of a raw event dict into UnifiedEvent."""ifisinstance(raw, UnifiedEvent):
returnrawifisinstance(raw, dict):
return_convert_event(raw)
returnraw# ← returns Any here, annotation says UnifiedEvent
Same issue: the fallthrough return raw can return a non-UnifiedEvent value.
Impact
MEDIUM: Both helpers are private (not public API), but they are called in every match-related public method on Router (fetch_market_matches, fetch_event_matches, fetch_matched_market_clusters, fetch_matched_event_clusters, compare_market_prices, fetch_hedges, fetch_arbitrage). Static analysis treats their return values as UnifiedMarket / UnifiedEvent with no warning, masking possible runtime errors when raw is neither a dict nor the expected type.
File
sdks/python/pmxt/router.pyImprecise Return Types (Type Lies)
Line 28 —
_parse_marketThe
elsebranch returnsrawunchanged, which is typedAny. The declared return type-> UnifiedMarketis false: callers believe they receive aUnifiedMarketbut may receive anything at runtime.Line 37 —
_parse_eventSame issue: the fallthrough
return rawcan return a non-UnifiedEventvalue.Impact
Router(fetch_market_matches,fetch_event_matches,fetch_matched_market_clusters,fetch_matched_event_clusters,compare_market_prices,fetch_hedges,fetch_arbitrage). Static analysis treats their return values asUnifiedMarket/UnifiedEventwith no warning, masking possible runtime errors whenrawis neither a dict nor the expected type.warn_return_any = truealready set inpyproject.toml, enablingdisallow_untyped_defs = true(issue [python-types] pyproject.toml: disallow_untyped_defs = false allows all type gaps to silently pass #246) will surface this as a mypy error.Suggested Fix
Option A — honest fallback with
Union:Option B — assert well-formedness and raise on unexpected input:
Option C — return
Anyand let callers narrow:Option B is safest for production correctness; Option A is the minimal change to fix the type lie.
Found by automated Python type hints audit