-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix test_io on windows #6387
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
Fix test_io on windows #6387
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThis pull request adds Destructor trait implementations to six IO classes in RustPython's stdlib module, enabling proper resource cleanup when these objects are garbage collected. Each class now declares Destructor in its pyclass declaration and implements slot_del to call close(). TextIOWrapper additionally gains Iterable and IterNext implementations. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Areas requiring extra attention:
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
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 |
|
Code has been automatically formatted The code in this PR has been formatted using git pull origin test-io |
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)
crates/vm/src/stdlib/io.rs (1)
1761-1771: Consider a macro for Destructor implementations (optional).There are now 7 nearly identical
Destructorimplementations. A macro could reduce duplication:macro_rules! impl_io_destructor { ($type:ty) => { impl Destructor for $type { fn slot_del(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<()> { let _ = vm.call_method(zelf, "close", ()); Ok(()) } #[cold] fn del(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<()> { unreachable!("slot_del is implemented") } } }; }However, this is entirely optional — the current explicit implementations are clear and maintainable.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_io.pyis excluded by!Lib/**
📒 Files selected for processing (2)
.github/workflows/ci.yaml(0 hunks)crates/vm/src/stdlib/io.rs(10 hunks)
💤 Files with no reviewable changes (1)
- .github/workflows/ci.yaml
🧰 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/stdlib/io.rs
🧠 Learnings (1)
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
Applied to files:
crates/vm/src/stdlib/io.rs
🔇 Additional comments (8)
crates/vm/src/stdlib/io.rs (8)
1755-1771: LGTM!The Destructor implementation for
BufferedReadercorrectly follows the established pattern from_IOBase, properly swallowing errors fromclose()which is appropriate behavior for a destructor.
1824-1840: LGTM!Consistent Destructor implementation for
BufferedWriter.
1878-1900: LGTM!Consistent Destructor implementation for
BufferedRandom.
1944-2003: LGTM!Consistent Destructor implementation for
BufferedRWPair.
2476-2479: LGTM!The
pyclassdeclaration correctly includesDestructor,Iterable, andIterNexttraits.
3342-3391: LGTM!The
TextIOWrapperimplementations are well-designed:
- Destructor: Follows the established pattern.
- Iterable: Correctly checks if closed before returning self as iterator.
- IterNext: Properly sets
telling = falseduring iteration (matching CPython behavior), releases the lock during thereadlinecall to avoid holding it during I/O, and correctly restores state onStopIteration.
4284-4292: LGTM!The necessary imports for
Destructorand related types are correctly added.
4551-4779: LGTM!The
FileIODestructor implementation is consistent with the other I/O types and correctly ensures proper cleanup.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.