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
{{ message }}
Repository navigation
Public to_decimal() helper accepts NaN/Infinity despite docstring promising safety #325
v2.5 #270 added an is_finite() guard to _coerce_decimal so a downstream NaN cannot ship the string "NaN" to a real-money endpoint. The sibling public helper to_decimal() — documented as the user-facing safe constructor — was not updated. to_decimal(float('nan')) returns Decimal('NaN') cleanly; to_decimal(float('inf')) returns Decimal('Infinity').
Users following the documented pattern of pre-coercing values with to_decimal() before passing them into model construction get a false sense of safety. Any code path that bypasses pydantic re-validation — direct Decimal arithmetic on to_decimal()'s output, then model_dump_json() on a hand-built dict, or pre-constructed Decimal values that match the field type and skip the BeforeValidator — ships "NaN" to the wire.
ifnotresult.is_finite():
raiseValueError("Decimal must be finite (got NaN/Infinity)")
returnresult
kalshi/types.py:94-107 — to_decimal skips the guard
defto_decimal(value: int|float|str|Decimal) ->Decimal:
"""Convert a user-supplied price/count value to Decimal safely. ... """ifisinstance(value, bool):
raiseTypeError(...)
ifisinstance(value, Decimal):
returnvaluereturnDecimal(str(value))
CHANGELOG.md:208 — #270 rejects NaN/Infinity at the boundary (only via _coerce_decimal).
Suggested fix
Replace the body of to_decimal() with a delegation to _coerce_decimal(value) so both code paths share the same is_finite() guard. Add a test_to_decimal_rejects_nan_inf regression test next to the existing TestToDecimal class.
Activity
fix(types): to_decimal NaN/Inf guard; Page._columns None-first nested…
release: 2.7.0 — post-v2.6 independent multi-LLM reviewer SDK audit c…