Fix windows socket#6408
Conversation
WalkthroughTwo public method signatures updated for improved type handling: Socket methods Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 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 |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/stdlib/src/socket.rs (1)
1462-1468: Verify Windows SOCKET handle range assumptions.The code assumes that socket handles fit within
i64::MAXon Windows. While this is true in practice (Windows SOCKET handles are kernel handles that won't exceed this range), the cast fromusize(which SOCKET is on 64-bit Windows) toi64could theoretically overflow for values abovei64::MAX.Consider adding a debug assertion or comment documenting this assumption.
#[pymethod] fn close(&self) -> io::Result<()> { let sock = self.detach(); + // Windows SOCKET handles are kernel handles that always fit in i64 if sock != INVALID_SOCKET as i64 { close_inner(sock as RawSocket)?; } Ok(()) }
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
Lib/test/test_selectors.pyis excluded by!Lib/**Lib/test/test_socketserver.pyis excluded by!Lib/**Lib/test/test_zipimport.pyis excluded by!Lib/**
📒 Files selected for processing (2)
crates/stdlib/src/socket.rs(2 hunks)crates/vm/src/stdlib/nt.rs(3 hunks)
🧰 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/nt.rscrates/stdlib/src/socket.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/nt.rs (1)
crates/wtf8/src/lib.rs (1)
from_wide(336-352)
⏰ 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). (10)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (3)
crates/stdlib/src/socket.rs (2)
1068-1068: LGTM!The
repr_strformatting correctly useszelf.fileno()directly now thatfileno()returnsi64instead ofRawSocket.
1478-1483: Thefileno()method correctly returnsi64for consistency withdetach().The implementation properly handles closed sockets by returning
INVALID_SOCKET as i64(-1) and correctly casts valid socket file descriptors toi64. The existing caller in__repr__(line 1068) is compatible with thei64return type.crates/vm/src/stdlib/nt.rs (1)
1125-1131: The function design is correct; no caller updates are needed.This is a
#[pyfunction]exposed to Python, not an internal Rust API. The#[pyfunction]macro automatically converts types implementingToPyObject(includingWtf8Bufand tuples thereof) to Python objects. The return type(Wtf8Buf, Wtf8Buf)correctly produces a Python tuple of two strings without requiring manual conversion by callers—there are no Rust callers to update.The
_vmparameter is unused but follows the established pattern in the codebase (e.g.,re.rs,gc.rs,typing.rs,os.rs,imp.rs) where unused parameters are retained for API consistency.Likely an incorrect or invalid review comment.
Sorry, something went wrong.
772b92e
into
RustPython:main
Dec 12, 2025
Summary by CodeRabbit
Release Notes
API Changes
fileno()anddetach()now return integer values instead of raw socket objects. Code using these methods may require updates.Refactoring
✏️ Tip: You can customize this high-level summary in your review settings.