Skip to content

Add more dict functions to c-api#8269

Merged
youknowone merged 2 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-final-dict
Jul 15, 2026
Merged

Add more dict functions to c-api#8269
youknowone merged 2 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-final-dict

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Expanded dictionary support in the C API with clear, set, get, and delete operations.
    • Added UTF-8 char* key variants for string-key interop, including a reference-style lookup with a hit/miss success flag.
    • Introduced error-aware vs raw lookups, with clearer behavior for misses and propagated errors.
  • Bug Fixes

    • Improved handling of invalid UTF-8 keys by raising appropriate Python decoding exceptions.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d58b2bcd-8754-4a23-b587-9523fb35baa3

📥 Commits

Reviewing files that changed from the base of the PR and between 60e37fd and 3db5877.

📒 Files selected for processing (1)
  • crates/capi/src/dictobject.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/capi/src/dictobject.rs

📝 Walkthrough

Walkthrough

The dictionary C-API gains clear, string-key set/delete, object-key lookup, and string-key lookup functions. String keys are decoded from C strings, with invalid UTF-8 handled according to each API’s return contract.

Changes

Dictionary C-API

Layer / File(s) Summary
Dictionary clearing and string-key mutation
crates/capi/src/dictobject.rs
Adds PyDict_Clear, PyDict_SetItemString, and PyDict_DelItemString, including UTF-8 decoding for string keys.
Object-key lookup
crates/capi/src/dictobject.rs
Adds PyDict_GetItem and PyDict_GetItemWithError with distinct missing-entry and error behavior.
String-key lookup
crates/capi/src/dictobject.rs
Adds PyDict_GetItemString and PyDict_GetItemStringRef, including raw-pointer results, out-parameter initialization, and invalid UTF-8 handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: youknowone

🚥 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 summarizes the main change: adding additional dict functions to the C API.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/dictobject.rs`:
- Around line 90-110: Update PyDict_GetItemString so CStr::to_str() failures
propagate an appropriate decode exception through the existing with_vm result
instead of returning Ok(null_mut()). Preserve Ok(None) as the lookup-miss path,
but stop swallowing errors from dict.inner_getitem_opt; only lookup misses
should return a null pointer without an exception.
🪄 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: 8701ac58-1d3c-4a57-b681-83a4a95747cd

📥 Commits

Reviewing files that changed from the base of the PR and between a9c2c52 and 03ed6cf.

📒 Files selected for processing (1)
  • crates/capi/src/dictobject.rs

Comment thread crates/capi/src/dictobject.rs
@bschoenmaeckers
bschoenmaeckers marked this pull request as draft July 14, 2026 21:24
@bschoenmaeckers
bschoenmaeckers marked this pull request as ready for review July 14, 2026 21:24

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@youknowone
youknowone merged commit 859516c into RustPython:main Jul 15, 2026
26 checks passed
@bschoenmaeckers
bschoenmaeckers deleted the c-api-final-dict branch July 15, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants