GeezerVison is showing github.com — Add iter support to c-api by bschoenmaeckers · Pull Request #8035 · RustPython/RustPython
Conversation
bschoenmaeckers
commented
Jun 3, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
- New Features
- Added a C API to compute an object's size.
- Added C API support for the iterator protocol: checking iterability, obtaining an iterator, and advancing/consuming iterator items.
- Added C API support for sending values into generators/coroutines and returning yielded or final values.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Jun 3, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

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: a3753766-ca68-4005-af5b-67132ae21efa
📥 Commits
Reviewing files that changed from the base of the PR and between 39772a7 and 21fffc5.
📒 Files selected for processing (2)
crates/capi/src/abstract_.rs
crates/capi/src/abstract_/iter.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- crates/capi/src/abstract_.rs
- crates/capi/src/abstract_/iter.rs
📝 Walkthrough
Walkthrough
Adds an iter submodule re-export and C-ABI FFI bindings for iterator operations (check, get-iter, next-item, next, send) plus a new PyObject_Size function that returns an object's length via obj.length(vm).
Changes
Iterator and Object Measurement C API Extension
| Layer / File(s) |
Summary |
Iterator module declaration and re-export crates/capi/src/abstract_.rs |
The iter submodule is declared and its public functions are re-exported via pub use iter::*;. |
Core iterator FFI interface crates/capi/src/abstract_/iter.rs |
Adds FFI imports and implements PyIter_Check, PyObject_GetIter, PyIter_NextItem, and PyIter_Next, translating iterator returns and StopIteration to C-visible results and out-pointers. |
Generator coroutine send semantics crates/capi/src/abstract_/iter.rs |
Implements PyIter_Send to downcast iterators to PyGenerator, call send, and return yielded values or StopIteration results via the out-pointer and boolean return. |
Object size measurement crates/capi/src/abstract_.rs |
Adds PyObject_Size, which invokes obj.length(vm) inside with_vm and returns the resulting size as isize. |
Iterator and generator validation tests crates/capi/src/abstract_/iter.rs |
Adds a compile-disabled (#[cfg(false)]) test module covering iterator next and generator send behavior using PyO3 test utilities. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested reviewers
Poem
A rabbit hops through FFI fields, 🐰
Yielding values, sending seals,
Sizes tallied, iterators stride,
C and Rust now walk side-by-side. ✨
🚥 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 'Add iter support to c-api' directly and clearly summarizes the main change: adding iterator-related C-ABI functions to the C API layer. |
| 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/capi/src/abstract_/iter.rs`:
- Around line 65-68: In PyIter_Send, change the current hard downcast to
PyGenerator so it matches CPython: first check if arg_obj.is_none(); if so,
attempt to downcast iter_obj to PyGenerator and call as_coro().send(...) when it
is a generator, but if it's not a generator call PyIter::new(iter_obj).next(vm)
to advance the iterator; if arg_obj is not None and iter_obj is not a
PyGenerator, raise a TypeError. Use the existing methods
try_downcast_ref::<PyGenerator>, PyGenerator::as_coro().send, and
PyIter::new(iter_obj).next(vm) to implement the fallback.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 6cd14683-2403-4826-83dd-15a54a1a8120
📥 Commits
Reviewing files that changed from the base of the PR and between 57d1695 and 39772a7.
📒 Files selected for processing (2)
crates/capi/src/abstract_.rs
crates/capi/src/abstract_/iter.rs
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|