GeezerVison is showing github.com — Add more object c-api's by bschoenmaeckers · Pull Request #8170 · RustPython/RustPython
Conversation
bschoenmaeckers
commented
Jun 25, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
-
New Features
- Expanded C API surface for object operations, including ASCII/bytes conversion, attribute deletion, generic attribute setting, and richer attribute-existence APIs.
- Added additional object helpers for negation, hashing, self-iteration, identity checks, and repr enter/leave recursion tracking.
-
Bug Fixes
- Improved robustness for invalid attribute name text: malformed UTF-8 now raises a proper
ValueError instead of triggering unexpected failures.
- Attribute existence checks now fail safely (returning
false while reporting the underlying error) rather than erroring unpredictably.
-
Other
- Improved rich-compare operator handling and constant lookup behavior.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Jun 25, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

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: 51ac15d2-af59-4882-a1f1-c22381247742
📥 Commits
Reviewing files that changed from the base of the PR and between f90995c and 640375f.
📒 Files selected for processing (2)
crates/capi/src/object.rs
crates/capi/src/util.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- crates/capi/src/util.rs
- crates/capi/src/object.rs
📝 Walkthrough
Walkthrough
This PR expands the object C-API with new attribute, deletion, comparison, hash, identity, iterator, and repr-recursion entry points. It also changes string attribute APIs to validate UTF-8 and adds isize FFI output support.
Changes
Object C-API updates
| Layer / File(s) |
Summary |
Constant lookup and support imports crates/capi/src/object.rs |
PyComparisonOp and hash_not_implemented are imported, and Py_GetConstantBorrowed/Py_GetConstant now share a helper over runtime singletons. |
String attribute access and conversions crates/capi/src/object.rs |
PyObject_GetAttrString, PyObject_GetOptionalAttrString, and PyObject_SetAttrString map invalid UTF-8 to ValueError, and PyObject_ASCII/PyObject_Bytes are exported. |
Attribute deletion and generic set crates/capi/src/object.rs |
PyObject_DelAttr, PyObject_DelAttrString, and PyObject_GenericSetAttr add delete support and route null values to deletion. |
Attribute existence APIs crates/capi/src/object.rs |
PyObject_HasAttr and PyObject_HasAttrString report failures through vm.run_unraisable(...), while PyObject_HasAttrStringWithError propagates decoding and lookup errors. |
Rich compare, hash, and repr exports crates/capi/src/object.rs |
PyObject_RichCompare now uses parse_richcompare_op to map operator IDs, and PyObject_Not, PyObject_Hash, PyObject_HashNotImplemented, PyObject_SelfIter, Py_Is, Py_IsNone, Py_ReprEnter, and Py_ReprLeave are added. |
isize FFI result support crates/capi/src/util.rs |
isize gets an FfiResult implementation with -1 as the error sentinel. |
Sequence Diagram(s)
sequenceDiagram
participant Caller as C API caller
participant HasAttr as PyObject_HasAttrString
participant Obj as obj.has_attr
participant Unraisable as vm.run_unraisable
Caller->>HasAttr: attr_name
HasAttr->>Obj: decode UTF-8 and look up attribute
alt lookup succeeds
Obj-->>HasAttr: bool
HasAttr-->>Caller: 0 or 1
else decode or lookup fails
HasAttr->>Unraisable: report error
HasAttr-->>Caller: false
end
Loading
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
Suggested reviewers
Poem
A rabbit hopped through C-API lace,
With hash and repr and attrs in place.
No UTF-8 tumble, just ValueError’s glow,
And -1 hops home when hash winds blow. 🐇
Thump-thump, the object forest sings!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
| Check name |
Status |
Explanation |
Resolution |
| Title check |
❓ Inconclusive |
The title is related, but it is too generic to clearly describe the main API additions and behavior changes. |
Use a more specific title, such as adding object-related C-API functions and attribute/hash/repr helpers. |
✅ Passed checks (4 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 94.29% 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.
❤️ Share
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 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/object.rs`:
- Around line 324-326: The UTF-8 decode failure in the attribute-name handling
path is being swallowed by returning false directly, so invalid input is not
reported through the unraisable error flow. Update the attr-name conversion
logic in PyObject_HasAttrString/object lookup handling to detect the to_str
failure, invoke vm.run_unraisable with the conversion error, and then return
false so it matches the forgiving HasAttr behavior and does not silently drop
the error.
🪄 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: 59a6987b-4a8a-45aa-af6e-46a55d8f57c3
📥 Commits
Reviewing files that changed from the base of the PR and between c876709 and f90995c.
📒 Files selected for processing (2)
crates/capi/src/object.rs
crates/capi/src/util.rs
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|