Cap float format precision at `INT_MAX - 1024` like CPython 3.14.8
Merged
SA
2mo ago+83+83+01234567890123456789-4-4-0123456789
CI's setup-python now resolves 3.14 to CPython 3.14.8, which bounds the precision of every float presentation by DOUBLE_TO_STRING_PRECISION_MAX (INT_MAX - 1024) and raises ValueError: precision too big above it, before looking at the value. Two test cases used 2**31 - 1 and so failed on the CPython side in test-rust.
- Apply the same cap in the format-spec formatter (
fstring.rs) for floats, complex values and ints under a float presentation, and in the%formatter forstrandbytestemplates.inf/nanare rejected too, matching CPython. - Add
value_error_precision_too_bigtoexception_private.rs. - Move the two asserts to the largest accepted precision and add boundary error cases to the four format test files, plus a check that a
strprecision stays unbounded.
Verified against a standalone CPython 3.14.8 build locally; note a local 3.14.7 still accepts up to INT_MAX, so the new error asserts need 3.14.8 on the CPython side.
š¤ Generated with Claude Code
https://claude.ai/code/session_01RtPaQCAGccBo8izUqsEGRr
Summary by cubic
Caps float format precision at INT_MAX - 1024 to match CPython 3.14.8, raising ValueError: precision too big above it before inspecting the value.
- CI's
setup-pythonnow checks for the newest 3.14 patch so all OS jobs agree on 3.14.8; the macOS runner was preinstalling 3.14.7, whose float-to-string conversion accepts up toINT_MAX. - Applies the cap in the format-spec and
%formatters forstrandbytestemplates, covering floats, complex values, ints under a float presentation, andinf/nan. - Adds
MAX_FLOAT_PRECISIONand avalue_error_precision_too_bighelper. - Moves the two test asserts to the largest accepted precision, adds boundary error cases to the four format test files, and checks that
strprecision stays unbounded.