Skip to content

Stub: allow custom imports#5877

Open
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/custom-imports
Open

Stub: allow custom imports#5877
Tpt wants to merge 1 commit intoPyO3:mainfrom
Tpt:tpt/custom-imports

Conversation

@Tpt
Copy link
Contributor

@Tpt Tpt commented Mar 13, 2026

This feature is required to allow user-provided custom type hint to import types

These imports are written in a small DSL on the module like:

#[pymodule(stubs = {
    from datetime import datetime as dt, time;
    from uuid import UUID;
})]

Then parsed, sent as an AST inside the introspection data (following the same AST format as the type hints) and serialized by the introspection crate that merges these imports with the auto generated ones

The #[pymodule] parameter is named stub because we might include some other features in the future like protocols

These imports are written in a small DSL like:
```rust
#[pymodule(stubs = {
    from datetime import datetime as dt, time;
    from uuid import UUID;
})]
```
Then parsed, sent as an AST inside the introspection data (following the same AST format as the type hints) and serialized by the introspection crate that merges these imports with the auto generated ones

The `#[pymodule]` parameter is named `stub` because we might include some other features in the future like protocols
@Tpt Tpt force-pushed the tpt/custom-imports branch from 3ac8fee to 4fbc371 Compare March 13, 2026 14:02
@Tpt Tpt marked this pull request as ready for review March 13, 2026 14:51
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