pyo3::type_object

Trait PyTypeInfo

Source
pub unsafe trait PyTypeInfo: Sized {
    const NAME: &'static str;
    const MODULE: Option<&'static str>;

    // Required method
    fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject;

    // Provided methods
    fn type_object(py: Python<'_>) -> Bound<'_, PyType> { ... }
    fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType> { ... }
    fn is_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
    fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool { ... }
    fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool { ... }
    fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool { ... }
}
Expand description

Python type information. All Python native types (e.g., PyDict) and #[pyclass] structs implement this trait.

This trait is marked unsafe because:

  • specifying the incorrect layout can lead to memory errors
  • the return value of type_object must always point to the same PyTypeObject instance

It is safely implemented by the pyclass macro.

§Safety

Implementations must provide an implementation for type_object_raw which infallibly produces a non-null pointer to the corresponding Python type object.

Required Associated Constants§

Source

const NAME: &'static str

Class name.

Source

const MODULE: Option<&'static str>

Module name, if any.

Required Methods§

Source

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.

Provided Methods§

Source

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.

Source

fn type_object_bound(py: Python<'_>) -> Bound<'_, PyType>

👎Deprecated since 0.23.0: renamed to PyTypeInfo::type_object

Deprecated name for PyTypeInfo::type_object.

Source

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.

Source

fn is_type_of_bound(object: &Bound<'_, PyAny>) -> bool

👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_type_of

Deprecated name for PyTypeInfo::is_type_of.

Source

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.

Source

fn is_exact_type_of_bound(object: &Bound<'_, PyAny>) -> bool

👎Deprecated since 0.23.0: renamed to PyTypeInfo::is_exact_type_of

Deprecated name for PyTypeInfo::is_exact_type_of.

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 PyTypeInfo for Coroutine

Available on crate feature experimental-async only.
Source§

const NAME: &'static str = "Coroutine"

Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Source§

impl PyTypeInfo for CancelledError

Source§

const NAME: &'static str = "CancelledError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for IncompleteReadError

Source§

const NAME: &'static str = "IncompleteReadError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for InvalidStateError

Source§

const NAME: &'static str = "InvalidStateError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for LimitOverrunError

Source§

const NAME: &'static str = "LimitOverrunError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for QueueEmpty

Source§

const NAME: &'static str = "QueueEmpty"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for QueueFull

Source§

const NAME: &'static str = "QueueFull"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for TimeoutError

Source§

const NAME: &'static str = "TimeoutError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for gaierror

Source§

const NAME: &'static str = "gaierror"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for herror

Source§

const NAME: &'static str = "herror"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for timeout

Source§

const NAME: &'static str = "timeout"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyArithmeticError

Source§

const NAME: &'static str = "PyArithmeticError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyAssertionError

Source§

const NAME: &'static str = "PyAssertionError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyAttributeError

Source§

const NAME: &'static str = "PyAttributeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBaseException

Source§

const NAME: &'static str = "PyBaseException"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBlockingIOError

Source§

const NAME: &'static str = "PyBlockingIOError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBrokenPipeError

Source§

const NAME: &'static str = "PyBrokenPipeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBufferError

Source§

const NAME: &'static str = "PyBufferError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBytesWarning

Source§

const NAME: &'static str = "PyBytesWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyChildProcessError

Source§

const NAME: &'static str = "PyChildProcessError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyConnectionAbortedError

Source§

const NAME: &'static str = "PyConnectionAbortedError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyConnectionError

Source§

const NAME: &'static str = "PyConnectionError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyConnectionRefusedError

Source§

const NAME: &'static str = "PyConnectionRefusedError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyConnectionResetError

Source§

const NAME: &'static str = "PyConnectionResetError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDeprecationWarning

Source§

const NAME: &'static str = "PyDeprecationWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyEOFError

Source§

const NAME: &'static str = "PyEOFError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyEnvironmentError

Source§

const NAME: &'static str = "PyEnvironmentError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyException

Source§

const NAME: &'static str = "PyException"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFileExistsError

Source§

const NAME: &'static str = "PyFileExistsError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFileNotFoundError

Source§

const NAME: &'static str = "PyFileNotFoundError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFloatingPointError

Source§

const NAME: &'static str = "PyFloatingPointError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFutureWarning

Source§

const NAME: &'static str = "PyFutureWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyGeneratorExit

Source§

const NAME: &'static str = "PyGeneratorExit"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyIOError

Source§

const NAME: &'static str = "PyIOError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyImportError

Source§

const NAME: &'static str = "PyImportError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyImportWarning

Source§

const NAME: &'static str = "PyImportWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyIndexError

Source§

const NAME: &'static str = "PyIndexError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyInterruptedError

Source§

const NAME: &'static str = "PyInterruptedError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyIsADirectoryError

Source§

const NAME: &'static str = "PyIsADirectoryError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyKeyError

Source§

const NAME: &'static str = "PyKeyError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyKeyboardInterrupt

Source§

const NAME: &'static str = "PyKeyboardInterrupt"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyLookupError

Source§

const NAME: &'static str = "PyLookupError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyMemoryError

Source§

const NAME: &'static str = "PyMemoryError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyModuleNotFoundError

Source§

const NAME: &'static str = "PyModuleNotFoundError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyNameError

Source§

const NAME: &'static str = "PyNameError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyNotADirectoryError

Source§

const NAME: &'static str = "PyNotADirectoryError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyNotImplementedError

Source§

const NAME: &'static str = "PyNotImplementedError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyOSError

Source§

const NAME: &'static str = "PyOSError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyOverflowError

Source§

const NAME: &'static str = "PyOverflowError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyPendingDeprecationWarning

Source§

const NAME: &'static str = "PyPendingDeprecationWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyPermissionError

Source§

const NAME: &'static str = "PyPermissionError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyProcessLookupError

Source§

const NAME: &'static str = "PyProcessLookupError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyRecursionError

Source§

const NAME: &'static str = "PyRecursionError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyReferenceError

Source§

const NAME: &'static str = "PyReferenceError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyResourceWarning

Source§

const NAME: &'static str = "PyResourceWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyRuntimeError

Source§

const NAME: &'static str = "PyRuntimeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyRuntimeWarning

Source§

const NAME: &'static str = "PyRuntimeWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyStopAsyncIteration

Source§

const NAME: &'static str = "PyStopAsyncIteration"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyStopIteration

Source§

const NAME: &'static str = "PyStopIteration"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySyntaxError

Source§

const NAME: &'static str = "PySyntaxError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySyntaxWarning

Source§

const NAME: &'static str = "PySyntaxWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySystemError

Source§

const NAME: &'static str = "PySystemError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySystemExit

Source§

const NAME: &'static str = "PySystemExit"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTimeoutError

Source§

const NAME: &'static str = "PyTimeoutError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTypeError

Source§

const NAME: &'static str = "PyTypeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnboundLocalError

Source§

const NAME: &'static str = "PyUnboundLocalError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnicodeDecodeError

Source§

const NAME: &'static str = "PyUnicodeDecodeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnicodeEncodeError

Source§

const NAME: &'static str = "PyUnicodeEncodeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnicodeError

Source§

const NAME: &'static str = "PyUnicodeError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnicodeTranslateError

Source§

const NAME: &'static str = "PyUnicodeTranslateError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUnicodeWarning

Source§

const NAME: &'static str = "PyUnicodeWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyUserWarning

Source§

const NAME: &'static str = "PyUserWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyValueError

Source§

const NAME: &'static str = "PyValueError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyWarning

Source§

const NAME: &'static str = "PyWarning"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyZeroDivisionError

Source§

const NAME: &'static str = "PyZeroDivisionError"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PanicException

Source§

const NAME: &'static str = "PanicException"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyAny

Source§

const NAME: &'static str = "PyAny"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBool

Source§

const NAME: &'static str = "PyBool"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyByteArray

Source§

const NAME: &'static str = "PyByteArray"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyBytes

Source§

const NAME: &'static str = "PyBytes"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyCapsule

Source§

const NAME: &'static str = "PyCapsule"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyCode

Available on non-Py_LIMITED_API and non-PyPy and non-GraalPy only.
Source§

const NAME: &'static str = "PyCode"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyComplex

Source§

const NAME: &'static str = "PyComplex"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDate

Available on non-Py_LIMITED_API only.
Source§

const NAME: &'static str = "PyDate"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDateTime

Available on non-Py_LIMITED_API only.
Source§

const NAME: &'static str = "PyDateTime"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDelta

Available on non-Py_LIMITED_API only.
Source§

const NAME: &'static str = "PyDelta"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTime

Available on non-Py_LIMITED_API only.
Source§

const NAME: &'static str = "PyTime"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTzInfo

Available on non-Py_LIMITED_API only.
Source§

const NAME: &'static str = "PyTzInfo"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDict

Source§

const NAME: &'static str = "PyDict"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDictItems

Source§

const NAME: &'static str = "PyDictItems"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDictKeys

Source§

const NAME: &'static str = "PyDictKeys"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyDictValues

Source§

const NAME: &'static str = "PyDictValues"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyEllipsis

Source§

const NAME: &'static str = "ellipsis"

Source§

const MODULE: Option<&'static str> = None

Source§

impl PyTypeInfo for PyFloat

Source§

const NAME: &'static str = "PyFloat"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFrame

Available on non-Py_LIMITED_API and non-PyPy and non-GraalPy only.
Source§

const NAME: &'static str = "PyFrame"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFrozenSet

Source§

const NAME: &'static str = "PyFrozenSet"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyCFunction

Source§

const NAME: &'static str = "PyCFunction"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyFunction

Source§

const NAME: &'static str = "PyFunction"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyList

Source§

const NAME: &'static str = "PyList"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyMappingProxy

Source§

const NAME: &'static str = "PyMappingProxy"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyMemoryView

Source§

const NAME: &'static str = "PyMemoryView"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyModule

Source§

const NAME: &'static str = "PyModule"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyNone

Source§

const NAME: &'static str = "NoneType"

Source§

const MODULE: Option<&'static str> = None

Source§

impl PyTypeInfo for PyNotImplemented

Source§

const NAME: &'static str = "NotImplementedType"

Source§

const MODULE: Option<&'static str> = None

Source§

impl PyTypeInfo for PyInt

Source§

const NAME: &'static str = "PyInt"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySuper

Available on neither PyPy nor GraalPy.
Source§

const NAME: &'static str = "PySuper"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySet

Source§

const NAME: &'static str = "PySet"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PySlice

Source§

const NAME: &'static str = "PySlice"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyString

Source§

const NAME: &'static str = "PyString"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTraceback

Source§

const NAME: &'static str = "PyTraceback"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyTuple

Source§

const NAME: &'static str = "PyTuple"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyType

Source§

const NAME: &'static str = "PyType"

Source§

const MODULE: Option<&'static str> = _

Source§

impl PyTypeInfo for PyWeakrefReference

Source§

const NAME: &'static str = "PyWeakrefReference"

Source§

const MODULE: Option<&'static str> = _

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here