Add more c-api error functions by bschoenmaeckers · Pull Request #7915 · 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: 32073fb1-a88b-49f0-b4fe-29d63ab33259
📒 Files selected for processing (3)
crates/capi/src/lib.rscrates/capi/src/pyerrors.rscrates/capi/src/traceback.rs
✅ Files skipped from review due to trivial changes (1)
- crates/capi/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- crates/capi/src/pyerrors.rs
- crates/capi/src/traceback.rs
📝 Walkthrough
Walkthrough
This PR adds C-API predicates and getters for exception inspection, an FFI binding PyTraceBack_Print that calls Python's traceback.print_tb inside the VM, and re-exports the traceback module from the crates/capi crate root.
Changes
Exception and Traceback C-API Bindings
| Layer / File(s) | Summary |
|---|---|
Exception inspection C-API crates/capi/src/pyerrors.rs |
Imports define_py_check, exports PyExceptionInstance_Check, adds PyExceptionClass_Check to test exception classes for subtype relationship, and implements PyException_GetTraceback, PyException_GetCause, and PyException_GetContext returning raw PyObject* or null. |
Traceback printing binding crates/capi/src/traceback.rs |
Defines PyTraceBack_Check predicate and implements pub unsafe extern "C" fn PyTraceBack_Print(tb, file) -> c_int which enters the VM, imports traceback, and calls print_tb(tb, file=...). |
Traceback module export crates/capi/src/lib.rs |
Adds pub mod traceback; to expose the traceback binding module from the crate root. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
- RustPython/RustPython#7787: Related changes to exception-typing support used by the new PyException* C-API functions.
- RustPython/RustPython#7871: Introduced the
define_py_check!macro machinery used to generate exported type/subtype predicates.
Suggested reviewers
- youknowone
Poem
🐰 With paws on keys and whiskers bright,
I call print_tb into the night.
Exceptions scanned and tracebacks shown,
The C-API sings in careful tone.
Hoppity hop — the bindings grown.
🚥 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 describes the addition of C-API error functions, which is partially reflected in the changeset. However, the changes also include traceback functionality (new traceback module export and PyTraceBack_Print), which goes beyond just error functions and is not mentioned in the title. |
| 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.