-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add callable validation to codecs.register_error
#6229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callable validation to codecs.register_error
#6229
Conversation
Validate that the handler argument passed to codecs.register_error is callable, raising TypeError with message 'handler must be callable' if it is not. This matches CPython behavior. This fix enables test_badregistercall in test_codeccallbacks.py to pass.
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
vm/src/stdlib/codecs.rs (1)
70-78: LGTM! The callable validation correctly matches CPython behavior.The implementation properly validates that the handler is callable before registration, and the error message matches CPython's expected output. The return type change to
PyResult<()>is consistent with other registration functions in this module (registerandunregister).Minor observation: Line 72 uses
.to_owned()to convert the string literal. Ifnew_type_erroracceptsimpl Into<String>, you could simplify this to just pass the string literal directly, but this is a very minor style point.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_codeccallbacks.pyis excluded by!Lib/**
📒 Files selected for processing (1)
vm/src/stdlib/codecs.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Format Rust code with the default rustfmt style (runcargo fmt)
Run clippy and fix any warnings or lints introduced by your changes
Follow Rust best practices for error handling and memory management
Files:
vm/src/stdlib/codecs.rs
{vm,stdlib}/**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use RustPython macros (
pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
vm/src/stdlib/codecs.rs
🧬 Code graph analysis (1)
vm/src/stdlib/codecs.rs (1)
vm/src/codecs.rs (1)
register_error(341-343)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run tests under miri
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Check Rust code with rustfmt and clippy
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Ensure compilation on various targets
youknowone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Validate that the handler argument passed to codecs.register_error is callable, raising TypeError with message 'handler must be callable' if it is not.
This fix enables test_badregistercall in test_codeccallbacks.py to pass.
Summary by CodeRabbit