Skip to content

Add bool support to c-api#7938

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

Add bool support to c-api#7938
bschoenmaeckers wants to merge 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-bool

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Contributor

@bschoenmaeckers bschoenmaeckers commented May 20, 2026

Summary by CodeRabbit

  • New Features
    • Extended the C API with new boolean type operations. Added functions for boolean type validation, testing whether values evaluate to true or false, and converting numeric values to boolean singletons. These additions improve compatibility for C-based extensions and third-party modules using boolean types.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 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: 441c7d2c-429d-4e25-be30-cee81eaeb8b8

📥 Commits

Reviewing files that changed from the base of the PR and between a6f13b9 and 3928248.

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

📝 Walkthrough

Walkthrough

A new boolobject module is added to the RustPython C-API layer with four exported functions: PyBool_Check (type validation), Py_IsTrue (true singleton test), Py_IsFalse (false singleton test), and PyBool_FromLong (construct boolean from c_long). The module is exported via lib.rs.

Changes

Boolean operations in C-API

Layer / File(s) Summary
Boolean type checks and conversion
crates/capi/src/boolobject.rs, crates/capi/src/lib.rs
New boolobject module exposes PyBool_Check, Py_IsTrue, Py_IsFalse, and PyBool_FromLong functions that wrap the VM's internal boolean singleton values and are exported from the crate.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • RustPython/RustPython#7872: Adds PyObject_IsTrue to the broader object C-API, while this PR introduces Py_IsTrue/Py_IsFalse specialized for boolean singletons.
  • RustPython/RustPython#7871: Uses the same define_py_check! macro pattern for type checks, showing shared C-API infrastructure for type validation functions.

Suggested reviewers

  • youknowone
  • ShaharNaveh

Poem

🐰 A boolean bunny hops into the fold,
With IsTrue and IsFalse, both brave and bold,
Check types and convert with C-ABI care,
The VM's singletons now everywhere! ✨

🚥 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 bool support to c-api' clearly and accurately summarizes the main change: adding boolean object support to the C-API layer, as evidenced by the new boolobject.rs module with PyBool functions.
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.

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