◐ Shell
clean mode source ↗

Add tuple support to c-api by bschoenmaeckers · Pull Request #7907 · RustPython/RustPython

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f418d16a-262d-4204-84f9-fda21108babd

📥 Commits

Reviewing files that changed from the base of the PR and between dfe90e5 and 8aebd8a.

📒 Files selected for processing (2)
  • crates/capi/src/lib.rs
  • crates/capi/src/tupleobject.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/capi/src/lib.rs
  • crates/capi/src/tupleobject.rs

📝 Walkthrough

Walkthrough

This PR adds Rust implementations of eight Python tuple C-API entry points (PyTuple_Check, PyTuple_CheckExact, PyTuple_New, PyTuple_FromArray, PyTuple_Size, PyTuple_GetItem, PyTuple_SetItem, PyTuple_GetSlice) and exports them through the tupleobject module, enabling external C code to create, access, and slice tuples while enforcing immutability.

Changes

Tuple C-API Implementation

Layer / File(s) Summary
Module export and type-check infrastructure
crates/capi/src/lib.rs, crates/capi/src/tupleobject.rs
Export the new tupleobject module and define PyTuple_Check/PyTuple_CheckExact type predicates via the C-API type-check macro infrastructure.
Tuple construction from C
crates/capi/src/tupleobject.rs
Implement PyTuple_New with optimized zero-length path and PyTuple_FromArray to construct tuples from raw C pointer arrays with size validation.
Tuple access, mutation, slicing, and validation
crates/capi/src/tupleobject.rs
Implement PyTuple_Size, PyTuple_GetItem, PyTuple_GetSlice for element and slice retrieval, PyTuple_SetItem as an immutability enforcement stub, and include disabled tests covering empty tuple and slice operations.

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • RustPython/RustPython#7871: The new PyTuple_Check/PyTuple_CheckExact exports rely on the define_py_check! macro added in that PR.

Suggested Reviewers

  • youknowone

Poem

🐰 Tuples take shape in the C API land,
With checks and creation carefully planned,
No setters allowed—they're immutable and bright,
Slices and gets make the bindings just right!

🚥 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 pull request title 'Add tuple support to c-api' directly and clearly summarizes the main change: adding C-API tuple functionality to the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.