PyModuleTypeAliasExt

Trait PyModuleTypeAliasExt 

Source
pub trait PyModuleTypeAliasExt {
    // Required method
    fn add_type_alias<T: PyTypeAlias>(&self) -> PyResult<()>;
}
Expand description

Extension trait for Bound<PyModule> to add type aliases.

This trait provides a convenient method for registering type aliases in Python modules.

§Example

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

#[pymodule]
fn my_module(m: &Bound<PyModule>) -> PyResult<()> {
    m.add_type_alias::<MyTypeAlias>()?;
    Ok(())
}

Required Methods§

Source

fn add_type_alias<T: PyTypeAlias>(&self) -> PyResult<()>

Adds a type alias to this module.

The type alias will be available as a module attribute with the name specified by T::NAME.

§Type Parameters
§Errors

Returns an error if:

  • Creating the type object fails
  • Adding the attribute to the module fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl PyModuleTypeAliasExt for Bound<'_, PyModule>

Source§

fn add_type_alias<T: PyTypeAlias>(&self) -> PyResult<()>

Implementors§