Skip to content

Implement PyModule_AddFunctions - #9484

Merged
youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-module-add-functions
Oct 30, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-module-add-functions

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added a C API function for registering multiple functions with a module. Registered functions are associated with the module’s name.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T12:55:28.959687Z b4d9e92 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d24ca41 and b4d9e92.

Files selected for processing: 1
  • crates/capi/src/modsupport.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Adds the exported C API function PyModule_AddFunctions. It builds functions from method definitions, assigns each function the module’s __name__, and stores each function in the module dictionary.

Changes: Module Function Registration

Layer / File(s) Summary
Register methods in a module
crates/capi/src/modsupport.rs
Adds PyModule_AddFunctions. It converts the module pointer, retrieves the module name, builds each method, assigns its __module__ attribute, and stores it in the module dictionary. Errors propagate through with_vm.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CCaller
  participant PyModule_AddFunctions
  participant with_vm
  participant build_method_def
  participant ModuleDictionary
  CCaller->>PyModule_AddFunctions: pass module pointer and method definitions
  PyModule_AddFunctions->>with_vm: run registration operation
  with_vm->>PyModule_AddFunctions: execute operation with VM
  PyModule_AddFunctions->>build_method_def: build function for each definition
  build_method_def-->>PyModule_AddFunctions: return function
  PyModule_AddFunctions->>ModuleDictionary: store function under method name
Loading

Possibly related PRs

Merge Risk: Minimal · up to b4d9e

The new module-function registration has no identified blocking issue and is mergeable subject to normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely names the main change: implementing PyModule_AddFunctions.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b4d9e928a6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/capi/src/modsupport.rs Resolved
Comment thread crates/capi/src/modsupport.rs Resolved
Comment thread crates/capi/src/modsupport.rs Resolved
@codspeed

codspeed Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing bschoenmaeckers:c-api-module-add-functions (b4d9e92) with main (d24ca41)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@youknowone
youknowone merged commit a0057a6 into RustPython:main Oct 30, 2026
21 checks passed
@bschoenmaeckers
bschoenmaeckers deleted the c-api-module-add-functions branch October 30, 2026 15:17
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