Cross-module inheritance#88
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements support for cross-module inheritance in generated pybind11 bindings by allowing a module to import other extension modules before registering its own classes, enabling externally-wrapped base types to be registered first (per #57 / pybind11 “partitioning code over multiple extension modules” guidance).
Changes:
- Add
importsto module configuration parsing (package_info.yaml→ModuleInfo) and emitpy::module_::import(...)statements at the start of generated modules. - Extend class wrapper generation to reference base classes by C++ type when the base is wrapped outside the current module.
- Add/extend the shapes example and tests to exercise cross-module inheritance (new
compositesmodule withSquareinheritingRectangle).
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_package_info_parser.py | Adds unit tests asserting module-level imports parsing and default behavior. |
| README.md | Documents the new imports mechanism for cross-module inheritance. |
| examples/shapes/wrapper/primitives/_pyshapes_primitives.main.cppwg.cpp | Demonstrates generated module-level import for dependency registration. |
| examples/shapes/wrapper/package_info.yaml | Adds imports usage and introduces the new composites module configuration. |
| examples/shapes/wrapper/composites/Square.cppwg.hpp | New generated header for Square registration. |
| examples/shapes/wrapper/composites/Square.cppwg.cpp | New generated wrapper registering Square with an external base (Rectangle). |
| examples/shapes/wrapper/composites/_pyshapes_composites.main.cppwg.cpp | New generated module that imports primitives before registering Square. |
| examples/shapes/src/py/tests/test_classes.py | Adds an integration test verifying cross-module inheritance behavior at runtime. |
| examples/shapes/src/py/pyshapes/composites/init.py | Exposes the composites extension module via Python package init. |
| examples/shapes/CMakeLists.txt | Builds the new composites extension module. |
| cppwg/writers/module_writer.py | Emits configured imports at the start of each generated PYBIND11_MODULE. |
| cppwg/writers/class_writer.py | Adds logic to include external base classes in py::class_ definitions. |
| cppwg/parsers/package_info_parser.py | Adds default imports: [] and parses module imports from YAML. |
| cppwg/info/module_info.py | Adds imports to ModuleInfo and documents intended usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supports #57