Skip to content

Pass owned iterables straight into PyIter - #8805

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowone:owned-get-iter
Sep 24, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowone:owned-get-iter

Conversation

@youknowone

@youknowone youknowone commented Sep 24, 2026 •

Copy link
Copy Markdown
Member
  • Closes #xxxx

One of checkbox below must be checked.

  • I did not use AI to write the code of this patch.
  • This PR follows our AI policy

Summary

GET_ITER, GET_YIELD_FROM_ITER, ** mapping keys(), and builtin iter() already hold a PyObjectRef. They called PyObject::get_iter, which cloned the object before PyIter::try_from_object. Pass the owned value through instead. get_iter stays for callers that only have a borrow.

Summary by CodeRabbit

  • Bug Fixes
    • Iterator creation across bytecode execution, mapping-key iteration, and the built-in iter function now uses a consistent conversion path. Objects that cannot be used as iterators may receive different type-validation behavior when passed to these operations.

GET_ITER, GET_YIELD_FROM_ITER, mapping keys(), and builtin iter()
already hold a PyObjectRef. get_iter() cloned it before try_from_object.

Assisted-by: Grok CLI:grok-4.7
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: RustPython/RustPython/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 28afab1a-e969-4e2d-937e-a5d6141d0a7b

📥 Commits

Reviewing files that changed from the base of the PR and between 0940849 and b509422.

📒 Files selected for processing (2)
  • crates/vm/src/frame.rs
  • crates/vm/src/stdlib/builtins.rs

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

Four iterator-creation call sites now use PyIter::try_from_object: two frame instruction handlers, mapping-key iteration, and the no-sentinel branch of the iter builtin.

Changes

Iterator construction

Layer / File(s) Summary
Iterator construction call sites
crates/vm/src/frame.rs, crates/vm/src/stdlib/builtins.rs
The GetIter and GetYieldFromIter handlers, mapping-key iteration, and the no-sentinel branch of iter now create iterators through PyIter::try_from_object.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to b5094

This change avoids an intermediate reference clone while preserving iterator conversion behavior. No merge-blocking risk is identified; it is ready for normal checks.

🚥 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 describes the main change: passing already-owned objects directly to PyIter to avoid unnecessary cloning at iterator creation call sites.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@youknowone
youknowone merged commit 9d8709e into RustPython:main Sep 24, 2026
30 checks passed
@youknowone
youknowone deleted the owned-get-iter branch September 24, 2026 06:32
@youknowone
youknowone restored the owned-get-iter branch September 24, 2026 07:00
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.

1 participant