Python ignores whitespace in format strings#6447
Conversation
WalkthroughThis PR adds three new spell-check dictionary entries (DICTFLAG, keeped, stginfo) and modifies the struct format string parser in the buffer module to skip whitespace after repeat counts and handle missing format specifiers based on whether a non-default repeat was specified. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ 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 |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.cspell.dict/cpython.txt(3 hunks)crates/vm/src/buffer.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/vm/src/buffer.rs
🔇 Additional comments (2)
crates/vm/src/buffer.rs (2)
241-244: No changes required—Python whitespace handling is correctly implemented.The code at lines 241-244 correctly skips the standard ASCII whitespace characters (space, tab, newline, carriage return) that Python's struct module ignores in format strings. The comment and implementation are both accurate.
247-257: Logic is correct; add edge case tests for whitespace handling.The implementation correctly handles format parsing with whitespace based on the official Python struct documentation. The error logic for "repeat count given without format specifier" appropriately distinguishes between explicit repeat counts and default repeats when trailing whitespace is encountered.
Consider adding tests to extra_tests/snippets/stdlib_struct.py to explicitly verify edge cases:
- Format with trailing whitespace:
"i "- Explicit repeat with trailing whitespace:
"3i "- Whitespace between repeat and format:
"3 i"These scenarios are not currently covered in the test file.
Sorry, something went wrong.
aef4de4
into
RustPython:main
Dec 16, 2025
Summary by CodeRabbit
Chores
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.