Skip to content

Add complex number support to c-api#7945

Open
bschoenmaeckers wants to merge 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-complex
Open

Add complex number support to c-api#7945
bschoenmaeckers wants to merge 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-complex

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Contributor

@bschoenmaeckers bschoenmaeckers commented May 21, 2026

Summary by CodeRabbit

Release Notes

  • New Features
    • Added complex number support to the C API, enabling creation of complex objects from real and imaginary values and extraction of their components.
    • Added type-checking functions for complex number validation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

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: 46d52998-9ce6-4764-a007-b756ba80dea8

📥 Commits

Reviewing files that changed from the base of the PR and between c845861 and 725025e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • crates/capi/Cargo.toml
  • crates/capi/src/complexobject.rs
  • crates/capi/src/lib.rs

📝 Walkthrough

Walkthrough

This PR introduces FFI bindings for Python complex number operations in RustPython. It adds the num-complex workspace dependency, implements three core FFI functions and type-check macros for complex number interop, and exposes the new module in the library's public API.

Changes

Complex number FFI bindings

Layer / File(s) Summary
Complex FFI binding setup
crates/capi/Cargo.toml, crates/capi/src/lib.rs
num-complex workspace dependency is added and the new complexobject module is declared public.
Complex FFI functions and tests
crates/capi/src/complexobject.rs
PyComplex_FromDoubles creates complex objects from c_double real and imaginary components; PyComplex_RealAsDouble and PyComplex_ImagAsDouble extract those components. Type-check macros PyComplex_Check and PyComplex_CheckExact are generated. A disabled test module provides a skeleton for validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • youknowone
  • ShaharNaveh

Poem

🐰 Complex numbers now have their FFI way,
Real and imaginary parts on display,
From doubles they're born, to doubles they flow,
RustPython's bridge makes the math dance so!

🚥 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 'Add complex number support to c-api' directly describes the main change: adding FFI bindings for Python complex numbers to the C API layer.
Docstring Coverage ✅ Passed Docstring coverage is 80.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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant