Match invalid format specifier error messages - #8477
Conversation
Assisted-by: Codex:gpt-5.6-sol
📦 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) [x] lib: cpython/Lib/ssl.py dependencies:
dependent tests: (53 tests)
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!
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.

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