Repository navigation
Match invalid format specifier error messages - #8477
youknowone merged 2 commits into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughBuilt-in boolean, complex, float, integer, and string formatting methods now use shared helpers to parse format specifications and convert formatting errors. Invalid-specifier errors include the specification and object type. ChangesFormat-spec parsing
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change makes invalid format specifier errors more detailed and consistent with CPython. No concrete merge-blocking risk was identified. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The change improves invalid-format diagnostics without expanding access or weakening the inspected formatting safeguards. No material security issue was identified in the change. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_format.py dependencies: dependent tests: (no tests depend on format) Legend:
|
let me think once again if this is the best way
youknowone
left a comment
There was a problem hiding this comment.
Hi! I left a change request not to make confusion to old path.
Sorry for late review!
| } | ||
| } | ||
|
|
||
| pub(crate) fn parse_format_spec( |
There was a problem hiding this comment.
due to this helper, FormatSpecError::InvalidFormatSpecifier arm in impl IntoPyException for FormatSpecError is now a trap. The error message will be diverged by its calling path.
if we go this direction, I prefer to remove impl IntoPyException for FormatSpecError and bring the implementation into this helper.
6e4ba86 to
dd16a10
Compare
Assisted-by: Codex:gpt-5.6-sol
InvalidFormatSpecifier needs the spec and the object type. Drop IntoPyException so that path cannot produce a generic message. Assisted-by: Grok:4.6
dd16a10 to
ebde064
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
This is a follow-up to #8475. RustPython still returned the generic
Invalid format specifiermessage for malformed format specifications, while CPython includes both the original specifier and the runtime object type.Add a VM-level format-spec parsing helper that maps only
InvalidFormatSpecifierto CPython's detailedValueErrormessage. Integer, boolean, float, complex, and string formatting now use the helper, including subclasses whose runtime type names must appear in the error.With the error text matching CPython, this enables the existing
test_better_error_message_format,test_unicode_in_error_message, andtest_specifier_z_errortests without changing their assertions or test data.Tests
cargo run --release -- -m test test_formatcargo test --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --exclude rustpython-capi(cd crates/capi && cargo test)— 102 passedcargo clippy --workspace --exclude rustpython_wasm --exclude rustpython-venvlauncher --all-targetsAI assistance
Codex (GPT-5.6) assisted with comparing CPython and RustPython error behavior, implementing the shared parsing helper, enabling the existing regression tests, running validation, and drafting this PR description. I reviewed the final diff and verified the behavior locally on macOS.
Summary by CodeRabbit