Add more dict functions to c-api by bschoenmaeckers · Pull Request #8043 · 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: 14c46398-1646-41fa-b930-3318324c5b5a
📒 Files selected for processing (2)
crates/capi/src/dictobject.rscrates/vm/src/builtins/dict.rs
📝 Walkthrough
Walkthrough
This PR extends RustPython's C-API with nine new dict operations and refactors the underlying PyDict merge logic to support conditional key overwrites. The C-API functions downcast PyObject pointers to PyDict and delegate to refactored merge methods that now accept an override_existing flag.
Changes
Dict C-API and merge refactoring
| Layer / File(s) | Summary |
|---|---|
PyDict merge refactoring with override parameter crates/vm/src/builtins/dict.rs |
Internal helper merge_object_with_override unifies dict-and-mapping merging; public merge_object enables overwrites, new merge_object_if_missing disables them. merge_dict and merge_from_seq2 accept override_existing flag and conditionally skip key inserts when false. |
Dict-or operator updates crates/vm/src/builtins/dict.rs |
__or__ and __ror__ operator implementations explicitly pass override=true to merge_dict for Python dict union semantics. |
C-API FFI dict operations crates/capi/src/dictobject.rs |
Nine new extern "C" functions (PyDict_Contains, PyDict_Copy, PyDict_DelItem, PyDict_Items, PyDict_Keys, PyDict_Values, PyDict_Merge, PyDict_Update, PyDict_MergeFromSeq2) downcast inputs to PyDict and delegate to refactored methods. Tests validate membership, copy/delete, collection views, update semantics, and sequence-pair merging with override handling. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- RustPython/RustPython#7929: Adds complementary C-API dict operations (
PyDict_New,PyDict_SetItem,PyDict_GetItem,PyDict_Size,PyDict_Next) to the samedictobject.rsmodule.
Suggested reviewers
- youknowone
- ShaharNaveh
Poem
🐰 Nine new pathways through the dict, so fine,
Override flags that merge with careful line,
C-API doors now open to the Python sea,
Keys skip or tumble—your choice shall be!
twitches nose ✨
🚥 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 more dict functions to c-api' directly describes the main change: adding new FFI functions for Python dict operations to the C API layer. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| 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.
Comment @coderabbitai help to get the list of available commands and usage tips.