Skip to content

Add macro for type check functions in c-api#7871

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

Add macro for type check functions in c-api#7871
bschoenmaeckers wants to merge 1 commit into
RustPython:mainfrom
bschoenmaeckers:c-api-type-check

Conversation

@bschoenmaeckers
Copy link
Copy Markdown
Contributor

@bschoenmaeckers bschoenmaeckers commented May 13, 2026

Summary by CodeRabbit

  • New Features
    • Enhanced C API with new type-checking functions for improved runtime type validation in extension modules
    • Added type relationship checking to enable inspection of type hierarchies
    • Expanded API capabilities for more sophisticated type operations and comparisons

Review Change Stack

@bschoenmaeckers bschoenmaeckers changed the title Add macro for type check function in c-api Add macro for type check functions in c-api May 13, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 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: c61b492e-cb41-4b82-b8ae-cc5ffaea4f52

📥 Commits

Reviewing files that changed from the base of the PR and between ef375be and 091172f.

📒 Files selected for processing (1)
  • crates/capi/src/object.rs

📝 Walkthrough

Walkthrough

This PR adds three C-exported functions to crates/capi/src/object.rs that expose Python type-checking capabilities: a macro generating PyType_Check (subtype-based validation) and PyType_CheckExact (exact-type validation), plus PyType_IsSubtype for querying type hierarchies.

Changes

Type-checking C API exports

Layer / File(s) Summary
Type-checking and type relationship functions
crates/capi/src/object.rs
define_py_check! macro generates PyType_Check and PyType_CheckExact for object validation; PyType_IsSubtype function queries type relationships between type objects. All use with_vm to access VM state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Three functions hop in to check,
What types and subtypes truly are,
Is this exact? Or down the tree?
The rabbit grins, the C APIs free,
Type checking made clear as a star! ⭐

🚥 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 macro for type check functions in c-api' directly and clearly describes the main change: introduction of a macro to generate type-checking functions for the C API.
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.

Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍

Comment thread crates/capi/src/object.rs
Comment on lines +35 to +36
define_py_check!(PyType_Check, types.type_type);
define_py_check!(exact PyType_CheckExact, types.type_type);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
define_py_check!(PyType_Check, types.type_type);
define_py_check!(exact PyType_CheckExact, types.type_type);
define_py_check!(fn PyType_Check, types.type_type);
define_py_check!(exact fn PyType_CheckExact, types.type_type);

I prefer to contains fn, struct, impl in macro to help searching fn PyType_Check. Otherwise the result will be zero.

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