Skip to content

Add seekable() to mmap.mmap - #8405

Merged
youknowone merged 3 commits into
RustPython:mainfrom
doma17:fix-mmap-seekable
Jul 29, 2026
Merged

youknowone merged 3 commits into
RustPython:mainfrom
doma17:fix-mmap-seekable

Conversation

@doma17

@doma17 doma17 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add mmap.mmap.seekable(), matching CPython for open and closed mappings.

Testing

  • cargo run --release -- -m test test_mmap
  • cargo run -- extra_tests/snippets/stdlib_mmap.py
  • cargo clippy -p rustpython-stdlib -- -D warnings
  • cargo test -p rustpython-stdlib
  • prek run --all-files
  • cd extra_tests && pytest -v (406 passed)

Summary by CodeRabbit

  • New Features

    • Added mmap.mmap.seekable() to report whether a memory-mapped object is seekable (always returns true).
  • Tests

    • Added coverage for seekable() on an in-memory mapping before and after closing it.

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
Copilot AI review requested due to automatic review settings July 28, 2026 04:02
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 88072716-13cb-47c9-ba55-e1dc1b01eab9

📥 Commits

Reviewing files that changed from the base of the PR and between 180979c and 77dd0e9.

📒 Files selected for processing (1)
  • crates/stdlib/src/mmap.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/stdlib/src/mmap.rs

📝 Walkthrough

Walkthrough

Adds mmap.mmap.seekable(), returning True, with tests confirming the result before and after the mapping is closed.

Changes

mmap seekability

Layer / File(s) Summary
Seekable method and validation
crates/stdlib/src/mmap.rs, extra_tests/snippets/stdlib_mmap.py
Adds PyMmap.seekable() returning True and tests the method on open and closed anonymous mappings.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding seekable() to mmap.mmap.
Linked Issues check ✅ Passed The PR implements mmap.mmap.seekable() and tests open and closed mappings, matching issue #8401.
Out of Scope Changes check ✅ Passed The changes stay focused on mmap.seekable() plus a targeted stdlib test snippet, with no unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Rust mmap stdlib module.
  • Add an extra_tests/snippets regression that asserts seekable() returns True both before and after close().

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' on Lib/test/test_mmap.py::MmapTests.test_basic appears 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.

Comment thread crates/stdlib/src/mmap.rs
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
Copilot AI review requested due to automatic review settings July 28, 2026 04:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread crates/stdlib/src/mmap.rs
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
Copilot AI review requested due to automatic review settings July 28, 2026 04:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@youknowone youknowone added z-ca-2026 Tag to track Contribution Academy 2026 and removed z-ca-2026 Tag to track Contribution Academy 2026 labels Jul 28, 2026
@youknowone
youknowone merged commit 942ddae into RustPython:main Jul 29, 2026
50 checks passed
youknowone pushed a commit that referenced this pull request Sep 16, 2026
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mmap.mmap is missing seekable()

3 participants