Skip to content

Add remaining float functions to c-api#8157

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

Add remaining float functions to c-api#8157
bschoenmaeckers wants to merge 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-more-float

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added C API support for converting strings to floating-point values.
    • Exposed floating-point helpers for retrieving minimum, maximum, and system float information.
  • Bug Fixes
    • Improved handling of invalid or null float-conversion inputs, returning a clear type error when appropriate.

@coderabbitai

coderabbitai Bot commented Jun 24, 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 433b50ca-f197-4839-861f-a3d9582877de

📥 Commits

Reviewing files that changed from the base of the PR and between bd0016f and 5ec6526.

📒 Files selected for processing (3)
  • crates/capi/src/floatobject.rs
  • crates/vm/src/builtins/float.rs
  • crates/vm/src/builtins/mod.rs
✅ Files skipped from review due to trivial changes (1)
  • crates/vm/src/builtins/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/vm/src/builtins/float.rs
  • crates/capi/src/floatobject.rs

📝 Walkthrough

Walkthrough

Adds four float C-API entry points: max/min getters, sys.float_info access, and string-to-float conversion. It also exposes the VM float parsing helper publicly so the C-API layer can reuse it.

Changes

Float C-API Extensions

Layer / File(s) Summary
Expose float_from_string as public API
crates/vm/src/builtins/float.rs, crates/vm/src/builtins/mod.rs
float_from_string gains pub visibility and is re-exported as parse_float_from_string from the builtins module.
C-API entry points implementation
crates/capi/src/floatobject.rs
Adds NonNull and AsObject imports, then implements PyFloat_GetMax, PyFloat_GetMin, PyFloat_GetInfo, and PyFloat_FromString with pointer validation and float parsing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐇 Hop, hop, the floats all sing,
Max and min in C-API spring.
A string becomes a floating glow,
And sys.float_info joins the show.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding missing float-related functions to the C API.
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.

@bschoenmaeckers bschoenmaeckers changed the title Add remaining float functions to c-apo Add remaining float functions to c-api Jun 24, 2026
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