Module runtime

Module runtime 

Source
Expand description

Runtime support for type aliases.

This module provides traits and utilities for registering type aliases in Python modules at runtime, enabling type aliases defined with type_alias! to be importable from Python.

§Example

use pyo3::prelude::*;
use pyo3_stub_gen::type_alias;
use pyo3_stub_gen::runtime::PyModuleTypeAliasExt;

// Define a runtime type alias
type_alias!("my_module", NumberOrString = i32 | String);

#[pymodule]
fn my_module(m: &Bound<PyModule>) -> PyResult<()> {
    // Register the type alias at runtime
    m.add_type_alias::<NumberOrString>()?;
    Ok(())
}

Traits§

PyModuleTypeAliasExt
Extension trait for Bound<PyModule> to add type aliases.
PyRuntimeType
Trait for Rust types that can be converted to Python type objects at runtime.
PyTypeAlias
Trait for type aliases that can be registered at runtime.

Functions§

union_type
Creates a Python union type using the | operator (Python 3.10+).