Add more object functions to c-api by bschoenmaeckers · Pull Request #8042 · 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: 40c88a66-ba33-465d-a036-d562e3d92809
📒 Files selected for processing (1)
crates/capi/src/object.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/capi/src/object.rs
📝 Walkthrough
Walkthrough
Adds multiple C-API object/type helpers (type module-name, optional/generic attr access, rich compare, callable/dir, generic dict get/set, weakref clearing) and makes VM object dict utilities and a weakref-clear method public and re-exported.
Changes
C-API Object Introspection and Manipulation Functions
| Layer / File(s) | Summary |
|---|---|
VM object utilities public API crates/vm/src/builtins/object.rs, crates/vm/src/builtins/mod.rs, crates/vm/src/object/core.rs |
object_get_dict and object_generic_set_dict changed from pub(crate) to pub and are re-exported; PyObject::clear_weak_refs() added to clear an object's weakref list. |
C-API object and type introspection functions crates/capi/src/object.rs |
Adds PyType_GetModuleName, PyObject_GetOptionalAttr, PyObject_HasAttrWithError, PyObject_GenericGetAttr, PyObject_RichCompare, PyCallable_Check, PyObject_ClearWeakRefs, PyObject_Dir, PyObject_GenericGetDict, and PyObject_GenericSetDict; updates FFI imports and includes a disabled test module. |
Sequence Diagram(s)
sequenceDiagram
participant CCaller
participant CApiLayer
participant VMBuiltins
participant VMCore
CCaller->>CApiLayer: PyObject_GetOptionalAttr(obj, name, out)
CApiLayer->>VMCore: generic_getattr / has_attr
VMCore-->>CApiLayer: attribute pointer / NULL
CCaller->>CApiLayer: PyObject_GenericSetDict(obj, value, ctx)
CApiLayer->>VMBuiltins: object_generic_set_dict(obj, value, vm)
VMBuiltins-->>CApiLayer: status (0/1)
CCaller->>CApiLayer: PyObject_ClearWeakRefs(obj)
CApiLayer->>VMCore: PyObject::clear_weak_refs()
VMCore-->>CApiLayer: cleared
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- RustPython/RustPython#7872: Overlapping C-API object/attribute helper extensions and placement of
PyObject_IsTrue. - RustPython/RustPython#7925: Related type-introspection C-API additions (type name/module helpers).
- RustPython/RustPython#7871: Additional
PyType_*C-API entry point changes related to type introspection.
Suggested reviewers
- youknowone
- ShaharNaveh
Poem
🐰 I hopped through code with nimble paws,
Exposed some attrs and cleared weak laws,
Dicts now open, comparisons sing,
C callers knock at every ring,
A rabbit cheers — the API claws!
🚥 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 accurately describes the main change: adding multiple new object functions to the C-API export surface in crates/capi/src/object.rs. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 84.21% 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.
Comment @coderabbitai help to get the list of available commands and usage tips.