◐ Shell
clean mode source ↗

Add _types module by youknowone · Pull Request #6807 · RustPython/RustPython

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Lib/test/test_reprlib.py is excluded by !Lib/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
📝 Walkthrough

Walkthrough

The changes refactor the builtin function and method type hierarchy to unify PyNativeFunction and PyNativeMethod under a shared "builtin_function_or_method" type with C-compatible representation, introduce a new PyCapsule type for capsule objects, and add a centralized _types module exposing all built-in Python type objects as accessor functions.

Changes

Cohort / File(s) Summary
Native Function & Method Type Unification
crates/vm/src/builtins/builtin_func.rs, crates/vm/src/function/method.rs
PyNativeFunction now includes #[repr(C)] annotation and expanded fields (value, zelf, module). PyNativeMethod inherits from PyNativeFunction and shares the builtin_function_or_method type. Introduces NativeFunctionOrMethod wrapper for common data access. Method building updated to use the unified type instead of distinct builtin_method_type.
Capsule Type Implementation
crates/vm/src/builtins/capsule.rs, crates/vm/src/builtins/mod.rs
New PyCapsule struct added with Representable and PyPayload trait implementations, producing <capsule object> repr. Module declaration and re-export added to builtins.
Built-in Type Exposure
crates/vm/src/stdlib/_types.rs, crates/vm/src/stdlib/mod.rs
New _types module created with 23+ accessor functions (AsyncGeneratorType, BuiltinFunctionType, CapsuleType, etc.) returning Python type objects from vm.ctx.types. Module integrated into builtin_module_defs initialization.
Type Registry Updates
crates/vm/src/types/zoo.rs
TypeZoo struct gains new capsule_type field. Capsule type initialized via PyCapsule::init_builtin_type(). builtin_function_or_method_type now reuses same type instance as builtin_method_type. Capsule initialization invoked in extension flow.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • arihant2math
  • coolreader18

Poem

A rabbit hops through builtin lands,
Native functions now join paws and hands,
Capsules bundled, types on display,
_types module lights the way,
One grand type zoo, hip hooray! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add _types module' accurately summarizes the main change: introducing a new _types module with type accessors, though it omits supporting infrastructure changes like PyCapsule and builtin_function_or_method consolidation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.