◐ Shell
clean mode source ↗

Add float support to c-api by bschoenmaeckers · Pull Request #7943 · 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: 6b865635-9563-4135-b3d7-40ea83486620

📥 Commits

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

📒 Files selected for processing (2)
  • crates/capi/src/floatobject.rs
  • crates/capi/src/lib.rs

📝 Walkthrough

Walkthrough

This PR adds a new C-API module for Python float objects to RustPython. It introduces type-check functions, float construction from C doubles, and value extraction with fallback conversion logic. The module is then exported from the crate root.

Changes

Float C-API bindings

Layer / File(s) Summary
Float C-API bindings implementation
crates/capi/src/floatobject.rs
PyFloat_Check and PyFloat_CheckExact verify float types via macro; PyFloat_FromDouble constructs a float in the VM from a c_double; PyFloat_AsDouble extracts the f64 value from a PyObject* with downcast and fallback conversion. A disabled test module supports future float interop verification.
Module export
crates/capi/src/lib.rs
The floatobject module is publicly exported from the crate root.

Possibly related PRs

  • RustPython/RustPython#7907: Adds similar extern "C" type-check functions in a new tupleobject C-API module using the same define_py_check! macro pattern.
  • RustPython/RustPython#7871: Introduces the define_py_check! macro that this PR leverages to generate PyFloat_Check and PyFloat_CheckExact.

Suggested reviewers

  • youknowone
  • ShaharNaveh

Poem

🐰 A float through the C-API air,
From doubles to objects with care,
PyFloat rises bright,
Type-checks done right,
RustPython's converter pair!


🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 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 float support to c-api' directly and clearly describes the main change: introducing C-API bindings for Python float objects (PyFloat_Check, PyFloat_CheckExact, PyFloat_FromDouble, and PyFloat_AsDouble).
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.

❤️ Share

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