Add set object functions to c-api#8002
Conversation
📝 WalkthroughWalkthroughThis PR adds CPython-style C-API bindings for Python set and frozenset types to RustPython. It exposes a new ChangesSet and FrozenSet C-API Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/setobject.rs`:
- Around line 45-50: PySet_Add currently downcasts the `set` argument only to
`PySet`, rejecting valid `PyFrozenSet` inputs; update `PySet_Add` (in
`crates/capi/src/setobject.rs`) to accept either a `PySet` or a `PyFrozenSet`
(and subtypes) by detecting the concrete type after `with_vm` unwrap and calling
the appropriate mutator: call `PySet::add` for `PySet` and invoke the VM-side
frozenset-initialization/mutation path for `PyFrozenSet` (the same internal
routine used to populate brand-new frozensets) so that `set.add(key, vm)`
semantics are preserved; ensure you clear/reset any cached hash on the
`PyFrozenSet` after mutation so subsequent hash lookups are correct and preserve
existing `with_vm` error propagation.
- Around line 82-90: Replace the current two-step membership + removal in
PySet_Discard with a single discard call that returns whether an item was
removed: add a bool-returning helper method on PySet (e.g.,
PySet::discard_returning_bool) that wraps the existing
PySetInner::discard(...)->PyResult<bool>, then update PySet_Discard to call that
helper once and return its boolean result as c_int; keep using the existing
try_downcast_ref::<PySet> and the same key handling but remove the prior
__contains__ probe so lookup+removal happen in one operation.
🪄 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: 20296950-c1ea-46f7-a7d7-1ad6bdea14cd
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (4)
crates/capi/Cargo.tomlcrates/capi/src/lib.rscrates/capi/src/setobject.rscrates/vm/src/builtins/set.rs
Sorry, something went wrong.
885cf5c
into
RustPython:main
Jun 1, 2026
I've used the skill from #8001 to implement the missing
setc-api functions using an AI agent.Summary by CodeRabbit
New Features
Chores
itertoolsas a workspace dependency.