Reject format spec with width above i32::MAX#7707
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFormat-spec parsing now validates parsed width values against Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_str.py (TODO: 14) dependencies: dependent tests: (no tests depend on str) Legend:
|
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