Add macro for type check functions in c-api by bschoenmaeckers · Pull Request #7871 · 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: c7fad624-873f-4cf8-8222-9dd4250cc2d6
📒 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 a macro-generated pair of C-exported functions PyType_Check (subtype) and PyType_CheckExact (exact match), plus PyType_IsSubtype(a, b); all run their checks inside with_vm and return results as c_int.
Changes
Type-checking C API exports
| Layer / File(s) | Summary |
|---|---|
Type-checking and type relationship functions crates/capi/src/object.rs |
define_py_check! macro defines PyType_Check and PyType_CheckExact to run subtype/exact checks against vm.ctx.types.type_type inside with_vm; PyType_IsSubtype dereferences *const PyTypeObject inputs, calls a.is_subtype(b) inside with_vm, and returns a c_int result. |
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant with_vm
participant vm_ctx_types_type_type
participant PyTypeObject
Caller->>with_vm: call PyType_Check(obj) / PyType_CheckExact(obj)
with_vm->>vm_ctx_types_type_type: compare obj.type against ctx.types.type_type
Caller->>with_vm: call PyType_IsSubtype(a, b)
with_vm->>PyTypeObject: call a.is_subtype(b)
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
- youknowone
Poem
🐰 I hopped through vm's cozy den,
Peeked at types and then again,
Exact or subtype — a tiny quest,
Returned a number, passed the test,
Hooray, C calls now know the rest!
🚥 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 a macro for type check functions in the C API, which aligns with the introduction of define_py_check! macro and the three exported type-checking functions. |
| 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.
Comment @coderabbitai help to get the list of available commands and usage tips.