Trait PyTypeMethods
pub trait PyTypeMethods<'py>: Sealed {
// Required methods
fn as_type_ptr(&self) -> *mut PyTypeObject;
fn name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ;
fn qualname(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ;
fn module(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ;
fn fully_qualified_name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ;
fn is_subclass(&self, other: &Bound<'_, PyAny>) -> Result<bool, PyErr> ⓘ;
fn is_subclass_of<T>(&self) -> Result<bool, PyErr> ⓘ
where T: PyTypeInfo;
fn mro(&self) -> Bound<'py, PyTuple>;
fn bases(&self) -> Bound<'py, PyTuple>;
}
dep_pyo3
and std
only.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§
fn as_type_ptr(&self) -> *mut PyTypeObject
fn as_type_ptr(&self) -> *mut PyTypeObject
Retrieves the underlying FFI pointer associated with this Python object.
fn name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
fn name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
Gets the name of the PyType
. Equivalent to self.__name__
in Python.
fn qualname(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
fn qualname(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
Gets the qualified name of the PyType
.
Equivalent to self.__qualname__
in Python.
fn module(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
fn module(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
Gets the name of the module defining the PyType
.
fn fully_qualified_name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
fn fully_qualified_name(&self) -> Result<Bound<'py, PyString>, PyErr> ⓘ
Gets the fully qualified name of the PyType
.
fn is_subclass(&self, other: &Bound<'_, PyAny>) -> Result<bool, PyErr> ⓘ
fn is_subclass(&self, other: &Bound<'_, PyAny>) -> Result<bool, PyErr> ⓘ
Checks whether self
is a subclass of other
.
Equivalent to the Python expression issubclass(self, other)
.
fn is_subclass_of<T>(&self) -> Result<bool, PyErr> ⓘwhere
T: PyTypeInfo,
fn is_subclass_of<T>(&self) -> Result<bool, PyErr> ⓘ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.
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.