Skip to content

Protocol-based single stub file for submodules#353

Draft
termoshtt wants to merge 1 commit intomainfrom
single-stub-file-for-submodules
Draft

Protocol-based single stub file for submodules#353
termoshtt wants to merge 1 commit intomainfrom
single-stub-file-for-submodules

Conversation

@termoshtt
Copy link
Copy Markdown
Member

Resolve #351

This commit adds a new specification document (docs/submodule.md) that
describes how to represent PyO3 submodules in Python stub files.

Key changes:
- Protocol-based representation: Submodules are represented as typed
  attributes using typing.Protocol, not as separate importable modules
- Single stub file generation: One .so file → one .pyi file for all
  layouts (Pure Rust and Mixed Python/Rust)
- Unique protocol naming: Each submodule gets a unique protocol name
  (e.g., _SubMod1Protocol, _SubMod2Protocol) to avoid naming conflicts
- Alignment with runtime behavior: Accurately reflects PyO3's module
  structure where submodules are attributes

This specification addresses issue #351 and simplifies the stub
generation strategy by eliminating the multi-file generation mechanism.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@termoshtt termoshtt self-assigned this Nov 8, 2025
@termoshtt termoshtt changed the title Single stub for submodule Protocol-based single stub file for submodules Nov 8, 2025
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.

Stub representation for PyO3 PyModule::add_submodule (non-importable “submodules”)

1 participant