Cap float format precision at `INT_MAX - 1024` like CPython 3.14.8

Merged
SA
2mo ago
+83-4

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 for str and bytes templates. inf/nan are rejected too, matching CPython.
  • Add value_error_precision_too_big to exception_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 str precision 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-python now 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 to INT_MAX.
  • Applies the cap in the format-spec and % formatters for str and bytes templates, covering floats, complex values, ints under a float presentation, and inf/nan.
  • Adds MAX_FLOAT_PRECISION and a value_error_precision_too_big helper.
  • Moves the two test asserts to the largest accepted precision, adds boundary error cases to the four format test files, and checks that str precision stays unbounded.