pyo3::prelude

Trait PyTypeMethods

Source
pub trait PyTypeMethods<'py>: Sealed {
    // Required methods
    fn as_type_ptr(&self) -> *mut PyTypeObject;
    fn name(&self) -> PyResult<Bound<'py, PyString>>;
    fn qualname(&self) -> PyResult<Bound<'py, PyString>>;
    fn module(&self) -> PyResult<Bound<'py, PyString>>;
    fn fully_qualified_name(&self) -> PyResult<Bound<'py, PyString>>;
    fn is_subclass(&self, other: &Bound<'_, PyAny>) -> PyResult<bool>;
    fn is_subclass_of<T>(&self) -> PyResult<bool>
       where T: PyTypeInfo;
    fn mro(&self) -> Bound<'py, PyTuple>;
    fn bases(&self) -> Bound<'py, PyTuple>;
}
Expand description

Implementation of functionality for PyType.

These methods are defined for the Bound<'py, PyType> smart pointer, so to use method call syntax these methods are separated into a trait, because stable Rust does not yet support arbitrary_self_types.

Required Methods§

Source

fn as_type_ptr(&self) -> *mut PyTypeObject

Retrieves the underlying FFI pointer associated with this Python object.

Source

fn name(&self) -> PyResult<Bound<'py, PyString>>

Gets the name of the PyType. Equivalent to self.__name__ in Python.

Source

fn qualname(&self) -> PyResult<Bound<'py, PyString>>

Gets the qualified name of the PyType. Equivalent to self.__qualname__ in Python.

Source

fn module(&self) -> PyResult<Bound<'py, PyString>>

Gets the name of the module defining the PyType.

Source

fn fully_qualified_name(&self) -> PyResult<Bound<'py, PyString>>

Gets the fully qualified name of the PyType.

Source

fn is_subclass(&self, other: &Bound<'_, PyAny>) -> PyResult<bool>

Checks whether self is a subclass of other.

Equivalent to the Python expression issubclass(self, other).

Source

fn is_subclass_of<T>(&self) -> PyResult<bool>
where T: PyTypeInfo,

Checks whether self is a subclass of type T.

Equivalent to the Python expression issubclass(self, T), if the type T is known at compile time.

Source

fn mro(&self) -> Bound<'py, PyTuple>

Return the method resolution order for this type.

Equivalent to the Python expression self.__mro__.

Source

fn bases(&self) -> Bound<'py, PyTuple>

Return Python bases

Equivalent to the Python expression self.__bases__.

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.

Implementors§

Source§

impl<'py> PyTypeMethods<'py> for Bound<'py, PyType>