Add seekable() to mmap.mmap - #8405
Conversation
mmap already supports seek() and tell(); expose seekable() to match CPython. Confidence: high Scope-risk: narrow Tested: test_mmap, stdlib_mmap snippet, clippy, prek, extra_tests Not-tested: full workspace test blocked by local rustpython-capi SIGSEGV Assisted-by: Codex:gpt-5.6-sol
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Changesmmap seekability
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Pull request overview
This PR adds the mmap.mmap.seekable() method to RustPython’s mmap implementation to match CPython behavior (returning True for both open and closed mappings), and adds a small regression snippet test.
Changes:
- Implement
mmap.mmap.seekable()in the Rustmmapstdlib module. - Add an
extra_tests/snippetsregression that assertsseekable()returnsTrueboth before and afterclose().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/stdlib/src/mmap.rs |
Adds the seekable() pymethod on the mmap type. |
extra_tests/snippets/stdlib_mmap.py |
Adds a snippet regression test covering seekable() on open/closed mappings. |
Comments suppressed due to low confidence (1)
crates/stdlib/src/mmap.rs:1147
- Now that
mmap.mmap.seekable()is implemented, the RustPython-specific@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: 'mmap' object has no attribute 'seekable'onLib/test/test_mmap.py::MmapTests.test_basicappears stale and should be removed/updated; otherwise the test may become an unexpected success once the underlying failure is fixed.
#[pymethod]
const fn seekable(&self) -> bool {
true
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CI ruff check removes the redundant blank line and treats the auto-fix as a failure. Constraint: CI runs prek with ruff check Confidence: high Scope-risk: narrow Tested: prek run --all-files; cargo run -- extra_tests/snippets/stdlib_mmap.py Assisted-by: Codex:gpt-5.6-sol
The method is invoked at runtime through the Python wrapper, so const qualification provides no benefit. Constraint: Python methods execute at runtime Confidence: high Scope-risk: narrow Tested: prek run --all-files; cargo run -- extra_tests/snippets/stdlib_mmap.py Assisted-by: Codex:gpt-5.6-sol
* Allow mmap-backed readers to identify seek support mmap already supports seek() and tell(); expose seekable() to match CPython. Confidence: high Scope-risk: narrow Tested: test_mmap, stdlib_mmap snippet, clippy, prek, extra_tests Not-tested: full workspace test blocked by local rustpython-capi SIGSEGV Assisted-by: Codex:gpt-5.6-sol * Keep mmap regression test lint-clean CI ruff check removes the redundant blank line and treats the auto-fix as a failure. Constraint: CI runs prek with ruff check Confidence: high Scope-risk: narrow Tested: prek run --all-files; cargo run -- extra_tests/snippets/stdlib_mmap.py Assisted-by: Codex:gpt-5.6-sol * Keep mmap seekability method conventional The method is invoked at runtime through the Python wrapper, so const qualification provides no benefit. Constraint: Python methods execute at runtime Confidence: high Scope-risk: narrow Tested: prek run --all-files; cargo run -- extra_tests/snippets/stdlib_mmap.py Assisted-by: Codex:gpt-5.6-sol
Summary
Add
mmap.mmap.seekable(), matching CPython for open and closed mappings.Testing
cargo run --release -- -m test test_mmapcargo run -- extra_tests/snippets/stdlib_mmap.pycargo clippy -p rustpython-stdlib -- -D warningscargo test -p rustpython-stdlibprek run --all-filescd extra_tests && pytest -v(406 passed)Summary by CodeRabbit
New Features
mmap.mmap.seekable()to report whether a memory-mapped object is seekable (always returnstrue).Tests
seekable()on an in-memory mapping before and after closing it.