reject SemLock reduce by youknowone · Pull Request #6738 · RustPython/RustPython
📝 Walkthrough
Walkthrough
A new __reduce__ method is added to the SemLock class in the multiprocessing module. This method raises a TypeError to prevent direct pickling of SemLock objects, requiring users to use the appropriate multiprocessing.SemLock wrapper for serialization support instead.
Changes
| Cohort / File(s) | Summary |
|---|---|
SemLock pickling restriction crates/stdlib/src/multiprocessing.rs |
Added __reduce__ method to SemLock class that raises TypeError with message "cannot pickle 'SemLock' object" to block direct serialization |
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~2 minutes
Possibly related PRs
- RustPython/RustPython#6542: Modifies the core
SemLockimplementation in multiprocessing module; this PR complements it by adding pickle prevention via the__reduce__method.
Poem
🐰 A lock that cannot be pickled sweet,
No brines nor jars shall make it neat,
For SemLock stays locked away,
Wrap it well, the proper way! 🔒
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'reject SemLock reduce' directly and specifically describes the main change: preventing SemLock objects from being pickled by implementing a reduce method that rejects serialization. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
- 📝 Generate docstrings
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_concurrent_futures/test_process_pool.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/stdlib/src/multiprocessing.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style usingcargo fmtto format Rust code
Always run clippy to lint 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/stdlib/src/multiprocessing.rs
🔇 Additional comments (1)
crates/stdlib/src/multiprocessing.rs (1)
550-555: LGTM!The
__reduce__method correctly prevents direct pickling ofSemLockobjects by raising aTypeError. This is consistent with CPython's behavior and the existing_rebuildclassmethod design pattern—the higher-levelmultiprocessing.synchronize.SemLockwrapper is expected to handle serialization while using_rebuildfor reconstruction.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
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 @coderabbitai help to get the list of available commands and usage tips.