`json.loads` ignores `sys.int_max_str_digits` (decodes an over-long int instead of raising `ValueError`)
Feature
json.loads should honor the interpreter's integer string-conversion limit (sys.set_int_max_str_digits, PEP 651). RustPython's native _json scanner (the Rust-implemented accelerated module, RustPython's analog of CPython's C _json) decodes an over-long integer literal instead of raising ValueError. The pure-Python decoder already honors the limit (its int conversion goes through int(str)); only the native _json scanner diverges.
Surfaced by running CPython's own stdlib test suite under RustPython — test_json.test_decode::TestCDecode.test_limit_int fails. The minimal standalone reproduction:
Reproduction
import sys, json sys.set_int_max_str_digits(5000) json.loads('1' * 5001)
CPython 3.14:
ValueError: Exceeds the limit (5000 digits) for integer string conversion: value has 5001 digits
RustPython:
(returns the 5001-digit integer — no error)
Python Documentation or reference to CPython source code
- Limit / API:
sys.set_int_max_str_digits(PEP 651). - CPython enforces it in
_match_number_unicode, which builds the int viaPyLong_FromString(limit-aware). - RustPython diverges in
JsonScanner::parse_number, which builds the integer withBigInt::from_str(buf)and never consultssys.int_max_str_digits.
Suggested fix
Route the integer construction through rustpython_common::int::bytes_to_int with the live vm.state.int_max_str_digits (the same path the int() builtin uses), so the limit is read per-call and sys.set_int_max_str_digits / adjust_int_max_str_digits take effect. Float parsing is unaffected. This also unblocks test_json.test_decode::TestCDecode.test_limit_int.
Investigated and drafted with AI assistance (Claude Code), reviewed by a human before filing, per RustPython's AI policy.