{{ message }}
Reject format spec with width above i32::MAX - #7707
Merged
Merged
Conversation
CPython rejects format-spec widths that exceed Py_ssize_t::MAX with ValueError: Too many decimal digits in format string. RustPython's FormatSpec::_parse only capped precision (via parse_precision); width was accepted up to usize::MAX, so values like sys.maxsize + 1 silently produced an effectively-ignored width. Reject any width above i32::MAX with FormatSpecError::DecimalDigitsTooMany, matching the existing precision cap and producing the byte-identical ValueError wording. Unmasks test_str.StrTest.test_format_huge_width.
Contributor
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Background
CPython rejects format-spec widths that exceed
Py_ssize_t::MAXwithValueError: Too many decimal digits in format string. RustPython'sFormatSpec::_parseonly capped precision (viaparse_precision); width digits were accepted up tousize::MAX, so values likesys.maxsize + 1silently produced an effectively-ignored width.Repro
Fix
After
parse_numberreturns the width inFormatSpec::_parse, reject any value abovei32::MAXwithFormatSpecError::DecimalDigitsTooMany. This matches the cap precision already uses and produces the byte-identical CPython"Too many decimal digits in format string"ValueError.Tests unmasked
test_str.StrTest.test_format_huge_widthVerification
test_format_huge_precisionstill passes with its existing"Precision too big"message)format(2.34, '100.3f')) still pad correctlytest_str,test_format,test_unicode_identifiers,test_fstring,test_int,test_float,test_decimalSummary by CodeRabbit
Release Notes